Nginx rewrite rule for favicon.ico files

nexon nginx-forum at
Fri Aug 31 13:53:42 UTC 2012

> Would this help? [note: from memory, not tested]
> location = /favicon.ico { 
>   try_files /images/$server_name.ico /favicon.ico =204;
> }
> M.
> _______________________________________________
> nginx mailing list
> nginx at

I have several vhosts, this is part of the config file for vhost in

server_name *;

if ($host ={
 rewrite ^/favicon.ico$ /favicon_mydomain.ico break;

if ($host ={
 rewrite ^/favicon.ico$ /favicon_boat.ico break;

if ($host ={
 rewrite ^/favicon.ico$ /favicon_car.ico break;


I plan to put all .ico files in /images/ dir.

and many more...

So what I need is next:
when request is happens for,
nginx searches for /images/favicon_car.ico and it serves it if exists,
if not than serves regular favicon.ico.

Please help...

Posted at Nginx Forum:,230375,230400#msg-230400

More information about the nginx mailing list