Nginx rewrite rule for favicon.ico files

nexon nginx-forum at nginx.us
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 nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

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

server_name  sub1.domain.com *.mydomain.com mydomain.com sub2.domain.com;


if ($host = www.mydomain.com){
 rewrite ^/favicon.ico$ /favicon_mydomain.ico break;
}

if ($host = boat.mydomain.com){
 rewrite ^/favicon.ico$ /favicon_boat.ico break;
}

if ($host = car.mydomain.com){
 rewrite ^/favicon.ico$ /favicon_car.ico break;
}

etc...

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

and many more...


So what I need is next:
when request is happens for car.mydomain.com,
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: http://forum.nginx.org/read.php?2,230375,230400#msg-230400



More information about the nginx mailing list