How to redirect all SSL traffic?

Igor Sysoev is at rambler-co.ru
Mon Nov 9 10:53:08 MSK 2009


On Sun, Nov 08, 2009 at 05:23:02PM -0700, Alex Hunsaker wrote:

> On Sun, Nov 8, 2009 at 15:25, Glen Lumanau <glen at lumanau.web.id> wrote:
> > Ok ill try that.
> >
> > Why we can't use the same method for port 443?
> 
> I assumed www.mydomain.com and mydomain.com have the same ip address
> and hence will go to the same nginx instance.  SSL only works with one
> ip (unless you are using TLS with the server name stuff) so the server
> { listen 443; } gets traffic for both www.mydomain.com and
> mydomain.com.  But it needs to redirect when it does not have the www
> to www.mydomain.com and also serve the real www.mydomain.com page when
> you go to www.mydomain.com. Hence the difference.
> 
> Im sure there are other ways to do it, experiment a bit :)

Anyway,

       server {
           listen 443;
           server_name  mydomain.com;
       }

       server {
           listen 443;
           server_name  www.mydomain.com;
       }

should work as well as

 if ($host !~ www\.mydomain\.com) {

however, using "if" is uneffective way.


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





More information about the nginx mailing list