Which is better?

Kiril Angov kupokomapa at gmail.com
Tue Apr 22 05:38:56 MSD 2008


I use two server blocks and everywhere I looked for examples they use
that. So i guess it is safe to use two server blocks as in your first
example it will check the regex every time you have a request, which
is slower than no regex at all :)

Kiril

On Mon, Apr 21, 2008 at 8:50 PM, mike <mike503 at gmail.com> wrote:
> Is one better than the other?
>
>  combining www. and non-www, and using a conditional:
>
>  server {
>     listen 80;
>     server_name michaelshadle.com www.michaelshadle.com;
>     ... index, root, all that stuff...
>
>     if ($http_host ~ "^www.(.*)") {
>         set $name $1;
>         rewrite ^/(.*) http://$name/$1 permanent;
>     }
>  }
>
>  or making two physical server blocks?
>
>  server {
>     listen 80;
>     server_name michaelshadle.com;
>     ... index, root, all that stuff...
>
>  }
>
>  server {
>     listen 80;
>     server_name www.michaelshadle.com;
>     rewrite ^/(.*) http://michaelshadle.com/$1 permanent;
>  }
>
>





More information about the nginx mailing list