Rewrite Performance Question

Igor Sysoev igor at sysoev.ru
Mon Jul 19 15:10:24 MSD 2010


On Mon, Jul 19, 2010 at 02:20:49PM +0400, Boris Dolgov wrote:

> On Mon, Jul 19, 2010 at 1:59 PM, Juergen Gotteswinter <jg at internetx.de> wrote:
> > Hi,
> >
> > come some take a look at these rewrite rules if they are ok regarding
> > performance?
> >
> >
> >        if ($host = 'forum.de' ) {
> >            rewrite ^/(.*)$ http://www.forum.de:81/$1 permanent;
> >        }
> >
> >        if ($host ~* ^(www\.)??forum\.(at|ch|com|eu|info|net|org)) {
> >            rewrite ^(.*)$ http://www.forum.de:81 last;
> >        break;
> >        }
> >   }
> Hi!
> Never use if ($host ...
> Different servers with different server_names must be used instead:
> server
> {
>     server_name forum.de;
>     location / { rewrite ^ http://www.forum.de:81/$request_uri? premanent; }
> }
> server
> {
>     server_name ~^(www\.)??forum\.(at|ch|com|eu|info|net|org);
>     location / { rewrite ^ http://www.forum.de:81/$request_uri? premanent; }
> }

Also, in the second server it's better to use usual names instead of regex:

     server_name   forum.at www.forum.at
                   forum.ch www.forum.ch
                   ...
                   ;


-- 
Igor Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list