[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nginx
Subject:    Re: Question about redirecting example for forcing a host name
From:       Igor Sysoev <is () rambler-co ! ru>
Date:       2007-08-28 16:20:48
Message-ID: 20070828162048.GP65072 () rambler-co ! ru
[Download RAW message or body]

On Tue, Aug 28, 2007 at 11:12:47AM -0500, Fred Palmer wrote:

> I found an Nginx example for forcing the host name and wanted to know if
> this is the best way to do it.  Basically I have several domains, some are
> misspellings of our primary domain and we want them to all go to our primary
> domain.  So I found this example:
> 
> server {
>   listen 80;
>   server_name example.com www.example.com;
> 
>   if ($host != 'example.com' ) {
>       rewrite  ^/(.*)$  http://example.com/$1  permanent;
>   }
> }
> 
> 
> Is this the best way?

No. You should route requests using "server", but not "if".

   server {
       listen  80;
       server_name   example.com;
       ...
   }

   # note "default", this server will receive all responses to 80 port,
   # that does not match "example.com".

   server {
       listen  80    default;
       server_name   www.example.com;
       rewrite       ...
   }


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



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic