Forum: NGINX Not logging access to favicon.ico

Posted by Mik J (Guest)
on 2013-01-17 22:36
(Received via mailing list)
Hello,


I'm really new to Nginx so forgive me if this question seems obvious to 
you.

I have Nginx with virtual hosts. In my nginx.conf I have
http {
...
include /etc/nginx/sites-enabled/*;
...

In /etc/nginx/sites-enabled/ I have my configuration such as default

server {
 listen 80 default_server;
 server_name _;
 index index.html;
 root /var/nginx/html;
 access_log /var/log/nginx/default.access.log;
}


I would like all my virtual hosts to have some global properties such as
location = /favicon.ico {
return 204;
access_log off;
log_not_found off;
}
so that I won't log access and errors relative to favicon.ico

But it's not clear to me, where I should put this statement in order to 
have a minimalistic configuration.


Thank you
Posted by Agus (Guest)
on 2013-01-17 23:54
(Received via mailing list)
location is only available in server block. Though you could create a 
file
with the location /favicon... and then include it in every server block
which will save you typing.





2013/1/17 Mik J <mikydevel@yahoo.fr>
Posted by Jonathan Matthews (Guest)
on 2013-01-18 00:22
(Received via mailing list)
On 17 January 2013 22:53, Agus <agus.262@gmail.com> wrote:
> location is only available in server block. Though you could create a file
> with the location /favicon... and then include it in every server block
> which will save you typing.

I do this. I'm /sure/ I've seen some historic user-agents requesting
"favico.ico" or something like that, so I place it under a location of
just /favico.

Mik - you may find that a 204 is not what you want to return, as
browsers /may/ not cache such a 0-byte file for the favicon. I use
this, and include it in every server{} stanza:

location /favico {
  access_log off;
  error_log /dev/null crit;
  empty_gif;
}

I'm fully aware it doesn't work on IE, due to IE only supporting
properly-formed Icon format files; fuck those guys.

Cheers,
Jonathan
--
Jonathan Matthews // Oxford, London, UK
http://www.jpluscplusm.com/contact.html
Posted by Mik J (Guest)
on 2013-01-18 09:01
(Received via mailing list)
----- Mail original -----

>  error_log /dev/null crit;
>  empty_gif;
> }


Thank you guys, so I'll put a somilar configuration as below for all my 
virtual hosts:
# cat /etc/nginx/sites-available/default
server {
 listen 80 default_server;
 server_name _;
 index index.html;
 root /var/nginx/html;
 access_log /var/log/nginx/default.access.log;

 location /favico {
 access_log off;
 error_log /dev/null crit;
 empty_gif;
 }
}

I was wondering that since this "location" block (and probably other 
settings) is going to be repeated in every one of my virtual hosts there 
would be a was to configure this globally.
I don't have any server stanza since I use include 
/etc/nginx/sites-enabled/*;
I'll do as Jonathan says except if someone has another suggestion.
Bye
Posted by Mark Alan (Guest)
on 2013-01-18 12:08
(Received via mailing list)
On Fri, 18 Jan 2013 08:00:54 +0000 (GMT), Mik J <mikydevel@yahoo.fr>
wrote:
>         access_log off;
>         error_log /dev/null crit;
>         empty_gif;
>         }
> }

There is no need to use the 'empty_gif' blob or the related
 ngx_http_empty_gif_module anymore.

Try this instead:

location = /favicon.ico { access_log off; log_not_found off; expires
30d; try_files /favicon.ico =204; }

Regarding that 204 status code, do see:
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#204

r.

M
Posted by "卫越" <weiyue@taobao.com> (Guest)
on 2013-01-23 04:35
(Received via mailing list)
You can try ngx_log_if module

https://github.com/cfsego/ngx_log_if


-----邮件原件-----
发件人: nginx-bounces@nginx.org [mailto:nginx-bounces@nginx.org] 代表 Mik J
发送时间: 2013年1月18日 16:01
收件人: nginx@nginx.org
主题: Re: Not logging access to favicon.ico



----- Mail original -----

>   error_log /dev/null crit;
>   empty_gif;
> }


Thank you guys, so I'll put a somilar configuration as below for all my 
virtual hosts:
# cat /etc/nginx/sites-available/default
server {
        listen 80 default_server;
        server_name _;
        index index.html;
        root /var/nginx/html;
        access_log /var/log/nginx/default.access.log;

        location /favico {
        access_log off;
        error_log /dev/null crit;
        empty_gif;
        }
}

I was wondering that since this "location" block (and probably other 
settings) is going to be repeated in every one of my virtual hosts there 
would be a was to configure this globally.
I don't have any server stanza since I use include 
/etc/nginx/sites-enabled/*;
I'll do as Jonathan says except if someone has another suggestion.
Bye


_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

________________________________

This email (including any attachments) is confidential and may be 
legally privileged. If you received this email in error, please delete 
it immediately and do not copy it or use it for any purpose or disclose 
its contents to any other person. Thank you.

本电邮(包括任何附件)可能含有机密资料并受法律保护。如您不是正确的收件人,请您立即删除本邮件。请不要将本电邮进行复制并用作任何其他用途、或透露本邮件之内容。谢谢。
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.