1

Greetings everyone!

I have a weird issue with nginx. I want to redirect all traffic that comes from domain.com to www.domain.com. I also want to redirect the secure one: https:// domain.com to https:// www.domain.com.

My config is:

server {
    listen           80;
    listen           443 ssl;
    server_name      domain.com;
    rewrite        ^ $scheme://www.domain.com$request_uri? permanent;
}

and under here is a server section to handle the www.domain.com

The domain.com immediately gets redirected to www.domain.com.

The secure one (https:// domain.com) does not. I get a warning that the certificate is issued to www.domain.com etc.

Any suggestions are more than welcome!

Thanks!

FYI: I am new at this so I don't know how to accept answers and stuff so that people get points. Excuse the noobness :)

1 Answer 1

1

You cannot fix this. In order to make the request the server must establish a secure connection. During the course of establishing that connection, the client is seeing the invalid certificate (www.domain.com != domain.com) and is throwing the error. Your redirect code is never being seen by the client because it abandons the call before it gets past the headers. There is nothing you can do except to buy and use a new cert for https://domain.com and then do the redirect.

2
  • Thank you for the answer Jack. I thought I was going nuts about it. Mar 30, 2011 at 21:42
  • +1, I just found this out the hard way. :) Got a non-wildcard certificate, was trying to redirect https://www.mysite.com to a non-www, and of course it doesn't match my cert. Oh well...
    – Cyclops
    Oct 24, 2011 at 14:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .