Access log off nginx not working?

I have the following drop.conf files located in /etc/nginx/drop.conf

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { allow all; access_log off; log_not_found off;
}
location = /apple-touch-icon.png { access_log off; log_not_found off; }
location = /apple-touch-icon-precomposed.png { access_log off;
log_not_found off; }
location ~ /. { deny all; access_log off; log_not_found off; }
location ~* ^/wp-content/uploads/..php$ {
deny all;
access_log off;
log_not_found off;
}
location ~
/files/(.*).php$ {
deny all;
access_log off;
log_not_found off;
}

Strange thing is when I include it in whichever server directive - ie in
whichever virtual host I have configured - I’m still getting favicon
logs in my access log. Is this a BUG ??
It looks like the include is simply not working ?

Example of the virtual host I’m including this in:

server {
listen 127.0.0.1:8080;
server_name .somehost.com;
root /var/www/somehost.com;

    access_log /var/log/nginx/somehost.com-access.nginx.log main;
error_log  /var/log/nginx/somehost.com-error.nginx.log;

    location ~* \.php.$ {
    # Proxy all requests with an URI ending with .php*
    # (includes PHP, PHP3, PHP4, PHP5...)
    include /etc/nginx/fastcgi.conf;
    }

    # all other files
    location / {
        root  /var/www/somehost.com;
    }

    error_page 404 /errors/404.html;
    location /errors/ {
            alias /var/www/errors/;
            internal;
    }

    #this loads custom logging configuration which disables favicon

error logging
include /etc/nginx/drop.conf;
}

yet in access logs for that domain im still seeing:

***** - - [06/Jul/2012:22:16:05 +0000] “GET /favicon.ico HTTP/1.1” 404
134 “-” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4)
AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47
Safari/536.11”
Yes I have restarted and reloaded nginx.

When I add a specific location directive directly to the virtual host
above and disable the include by commenting it in, favicon.ico requests
ARE STILL being logged. ie. I comment in include bit and add the
following to the above virtual host:

#include /etc/nginx/drop.conf;
location = /favicon.ico { access_log off; log_not_found off; }

Am I missing out something really obvious ? Or is this is a BUG ?
Cheers

Posted at Nginx Forum:

Hello!

On Fri, Jul 06, 2012 at 07:45:29PM -0400, gyre007 wrote:

I have the following drop.conf files located in /etc/nginx/drop.conf

location = /favicon.ico { access_log off; log_not_found off; }

[…]

Strange thing is when I include it in whichever server directive - ie in
whichever virtual host I have configured - I’m still getting favicon
logs in my access log. Is this a BUG ??
It looks like the include is simply not working ?

Example of the virtual host I’m including this in:

server {

[…]

    error_page 404 /errors/404.html;
    location /errors/ {
            alias /var/www/errors/;
            internal;
    }

[…]

***** - - [06/Jul/2012:22:16:05 +0000] “GET /favicon.ico HTTP/1.1” 404
134 “-” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4)
AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47
Safari/536.11”

[…]

Am I missing out something really obvious ?

Requests are logged in context of a location where request
execution ends up. As you have error_page 404 defined, and no
favicon.ico file - error 404 is generated and redirected to
/errors/404.html. As a result request is logged in context of
“location /errors/” where you have access log enabled.

Maxim D.

On Saturday 07 July 2012 17:52:52 gyre007 wrote:
[…]

The problem with this configuration is that the drop.conf file is
completely “ignored” because of what you said - so when I take
error_page bit out then drop.conf file is suddenly taken into account
and favicon.ico is no longer being logged. The question is how do I
handle this situation -> return 404 page when someone is accessing non
existing PHP URI and at the same time disable logging as per drop.conf
file ? Im banging my head against the table.
Any help appreciated.

error_page 404 /errors/404.html;

location /errors/ {
internal;
root /var/www;
}

location /errors/nolog/ {
internal;
alias /var/www/errors/;
access_log off;
}

location = /favicon.ico {
error_page 404 /errors/nolog/404.html;
log_not_found off;
}

etc…

wbr, Valentin V. Bartenev

On Sat, Jul 07, 2012 at 11:23:32AM +0400, Maxim D. wrote:

logs in my access log. Is this a BUG ??
alias /var/www/errors/;
[…]

Am I missing out something really obvious ?

Requests are logged in context of a location where request
execution ends up. As you have error_page 404 defined, and no
favicon.ico file - error 404 is generated and redirected to
/errors/404.html. As a result request is logged in context of
“location /errors/” where you have access log enabled.

And BTW, this is documented here:
http://nginx.org/en/docs/http/ngx_http_log_module.html

Hi Max,

Maxim D.

thanks for the explanation - that was my initial thought too but as I’m
rookie I wasn’t sure. Thanks again.
In that case I’m hitting a wall while trying to figure out how to
configure my server for the following scenario.
I have fastcgi_intercept_errors set in http block and have put
error_pages directive in the virtual host definition above to handle the
cases when someone tries to access PHP URI which does not exist – if I
take it away then Im getting “no input file specified” – which I
know makes sense as PHP-FPM is not able to find given file and reports
back to browser.

The problem with this configuration is that the drop.conf file is
completely “ignored” because of what you said - so when I take
error_page bit out then drop.conf file is suddenly taken into account
and favicon.ico is no longer being logged. The question is how do I
handle this situation → return 404 page when someone is accessing non
existing PHP URI and at the same time disable logging as per drop.conf
file ? Im banging my head against the table.
Any help appreciated.

Posted at Nginx Forum: