Custom 404 error_page seems to conflict with access_log off

Hello,

In my server block, I configured a custom 404 error page and I tried to
disable access log for /favicon.ico

error_page 404 /404.html;
location = /favicon.ico {
access_log off;
}

It seems that both conflicts.

When favicon.ico is present:
curl -I http://mydomain.com/favicon.ico reports 200 status code and
nothing
gets logged into my access log

When favicon.ico is missing:
curl -I http://mydomain.com/favicon.ico reports 404 status code
curl http://mydomain.com/favicon.ico displays my custom 404 html page
and strangely the 404 error gets logged into my access log: “HEAD
/favicon.ico HTTP/1.1” 404 0 “-” “curl/7.19.7
(universal-apple-darwin10.0)
libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3”

When I comment out #error_page 404 /404.html; when favicon.ico is
missing:
curl -I http://mydomain.com/favicon.ico reports 404 status code
curl http://mydomain.com/favicon.ico displays nginx’s default 404 page
nothing gets logged into my access log

Can someone explain me this behavior?

Thank you,
G.

Hello!

On Sun, Feb 26, 2012 at 08:43:07PM +0100, Grégory Pakosz wrote:

error_page 404 /404.html; VS access_log off; - Pastebin.com
and strangely the 404 error gets logged into my access log: “HEAD
/favicon.ico HTTP/1.1” 404 0 “-” “curl/7.19.7 (universal-apple-darwin10.0)
libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3”

When I comment out #error_page 404 /404.html; when favicon.ico is missing:
curl -I http://mydomain.com/favicon.ico reports 404 status code
curl http://mydomain.com/favicon.ico displays nginx’s default 404 page
nothing gets logged into my access log

Can someone explain me this behavior?

Requests are logged in a context of a location where processing ends.

That is, if you have 404 error_page configured requests to a
missing favicon.ico file are internally redirected to /404.html,
and handled in an appropriate location, not in location =
/favicon.ico where you have access_log switched off.

Maxim D.

On 26 Fev 2012 20h43 CET, [email protected] wrote:

This is what I usually employ for battling the dreaded missing favicon
error.

location = /favicon.ico {
access_log off;
try_files $uri @empty;
}

location @empty {
empty_gif; # send a in-memory 1x1 transparent GIF
}

If you prefer to just send a 204, do:

location = /favicon.ico {
access_log off;
try_files $uri =204;
}

HTH,
— appa

27 февраля 2012, 00:57 от Maxim D. [email protected]:

location = /favicon.ico {

nothing gets logged into my access log

Can someone explain me this behavior?

Requests are logged in a context of a location where processing ends.

That is, if you have 404 error_page configured requests to a
missing favicon.ico file are internally redirected to /404.html,
and handled in an appropriate location, not in location =
/favicon.ico where you have access_log switched off.

You may want to use the following to minimize the overhead
caused by useless requests for the missing favicon.ico file:

location = /favicon.ico {
access_log off;
return 204;
}

Max