0

I have the following code:

server {
listen 443;
server_name www.domain.com;

ssl on;
ssl_certificate    /etc/nginx/ssl/domain.com.crt;
ssl_certificate_key    /etc/nginx/ssl/domain.com.key;

return 301 https://domain.com$request_uri;
}

If I access https://domain.com everything works, if I access https://www.domain.com I get a SSL warning that the Certificate does not match the domain, which it doesn't. Once you accept the invalid SSL cert it redirects you to https://domain.com with the valid cert.

But if I remove the ssl on; bit etc, then neither https://domain.com or https://www.domain.com work.

So how can I remove the WWW without the SSL Invalid warning?

I only have an SSL cert for domain.com and not for www.domain.com.

migrated from superuser.com May 8 '14 at 1:59

This question came from our site for computer enthusiasts and power users.

1

HTTPS is HTTP over in TLS/SSL connection. Before any HTTP transaction, the client must be verify server certificate through SSL-Handshake ritual. Your redirection, which is HTTP transaction, will be start after SSL-Handshake.

If you want https://www.domain.com redirect to https://domain.com without SSL Invalid warning, your certificate must be valid to both domain.com and www.domain.com.

The simplest way is ask your CA to append www.domain.com to subjectAltName field in your certificate, so you can serve multiple domain with one certificate. Some CAs will do it without cost. The other options is obtain new certificate for www.domain.com although it's pretty overkill.

  • Ah yes, was afraid of that. I have very limited time, hoped there was a coded way. Thanks :) – Nicekiwi May 8 '14 at 2:04
  • Ha, looks like my Host screwed up creating the SSL cert. It is supposed to cover www, but it didn't! They've giving me a new one free. :) – Nicekiwi May 8 '14 at 2:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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