# Custom 404 error\_page seems to conflict with access\_log off

**URL:** <https://www.ruby-forum.com/t/custom-404-error-page-seems-to-conflict-with-access-log-off/217274>\
**Category:** NGINX\
**Created:** [February 26, 2012, 8:46pm UTC](https://www.ruby-forum.com/t/custom-404-error-page-seems-to-conflict-with-access-log-off/217274 "2012-02-26T20:46:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 26, 2012, 8:46pm UTC](https://www.ruby-forum.com/t/custom-404-error-page-seems-to-conflict-with-access-log-off/217274/1 "2012-02-26T20:46:35Z")

</div>

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;  
}

> **[error\_page 404 /404.html; VS access\_log off; - Pastebin.com](https://pastebin.com/39qXWuq2)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

It seems that both conflicts.

When favicon.ico is present:  
curl -I [http://mydomain.com/favicon.ico](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](http://mydomain.com/favicon.ico) reports 404 status code  
curl [http://mydomain.com/favicon.ico](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](http://mydomain.com/favicon.ico) reports 404 status code  
curl [http://mydomain.com/favicon.ico](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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 26, 2012, 9:57pm UTC](https://www.ruby-forum.com/t/custom-404-error-page-seems-to-conflict-with-access-log-off/217274/2 "2012-02-26T21:57:47Z")

</div>

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](http://pastebin.com/39qXWuq2)  
> 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](http://mydomain.com/favicon.ico) reports 404 status code  
> curl [http://mydomain.com/favicon.ico](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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 27, 2012, 12:08am UTC](https://www.ruby-forum.com/t/custom-404-error-page-seems-to-conflict-with-access-log-off/217274/3 "2012-02-27T00:08:10Z")

</div>

On 26 Fev 2012 20h43 CET, removed\_email\_address@domain.invalid 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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 26, 2012, 11:18pm UTC](https://www.ruby-forum.com/t/custom-404-error-page-seems-to-conflict-with-access-log-off/217274/4 "2012-02-26T23:18:04Z")

</div>

27 февраля 2012, 00:57 от Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 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
