Nginx rewrite rule for favicon.ico files

nexon nginx-forum at nginx.us
Fri Aug 31 13:52:48 UTC 2012


Igor Sysoev Wrote:
-------------------------------------------------------
> On Aug 31, 2012, at 15:44 , nexon wrote:
> 
> >> Anything except favicons in this servers is the same ?
> > 
> > Please explain your question.
> > If I understand you correctly, you are asking is every subdomain
> have their
> > own page, than yes.
> > The trick is that if subdomain have it's own favicon than it needs
> to be
> > served with it, if not, than to be served with main favicon.ico...
> 
> The question is why do you try to push everything inside one server
> instead of separating processing in several servers:
> 
> server {
>     server_name  sub1.domain.com;
>     ...
> }
> 
> server {
>     server_name  sub2.domain.com;
>     ...
> }
> 
> server {
>     server_name  sub3.domain.com;
>     ...
> }
> 
> 
> --
> Igor Sysoev
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

I am using several vhosts and this is part of the setup file for one of
them:

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

if ($host = something1.domain.com){
 rewrite ^/favicon.ico$ /favicon_domain.com.ico break;
}

if ($host = something2.domain.com){
 rewrite ^/favicon.ico$ /favicon_domain.com.ico break;
}

etc...

I plan to put all *.ico files in location /images/

something1.domain.com.ico
something2.domain.com.ico
something3.domain.com.ico

etc...

So what I need is:
 when request is for something1.domain.com.ico happens
than to check in location /images/ is there a file something1.domain.com.ico
and serve it if it is there, 
but if there is no such a file, than to serve clasic favicon.ico file.

Please help...

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,230375,230394#msg-230394



More information about the nginx mailing list