Score:0

Do not log access to some php scripts

ro flag

I would like to exclude from access.log access to some php scripts. To do this, I did the following:

 location ~ ^/lib/exe/(jquery|taskrunner|css|js)\.php$ {
        access_log off; 
        #access_log /var/log/nginx/test_access.log;
        try_files /dev/null/1 @processphp;
    }   

    location ~ \.php$ {
        try_files /dev/null/1 @processphp;
    }   

    location @processphp {
        if (!-f $request_filename) { return 404; }
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param REDIRECT_STATUS 200;
    
        # send to fastcgi
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        include snippets/fastcgi-php.conf;    
    }

But unfortunately, it didn't work. /lib/exe/jquery.php /lib/exe/js.php /lib/exe/css.php /lib/exe/taskrunner.php are still in access.log.

Tell me please, how can I do what I want?

Score:0
ro flag

I think I managed to do it!

http {
...
    map $request_filename $log {
        default 1;
       "~/(jquery|js|css|taskrunner)\.php" 0;
    }
...

server {
    ...
    location ~ \.php$ {
            access_log /var/log/nginx/access.log combined if=$log;
            if (!-f $request_filename) { return 404; }
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param REDIRECT_STATUS 200;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            include snippets/fastcgi-php.conf;
    }
...

But I will be glad if someone offers a better option!

Docs:

Prem avatar
cn flag
In "Original Case" , you have `/lib/exe/(...)` , while in "New Case" , you have `~/(...)` : You could try the Same in "Original Case" too , it should then work.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.