Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 :)

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Thank you for the answer Jack. I thought I was going nuts about it. –  Nikolaos Dimopoulos Mar 30 '11 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 '11 at 14:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.