: Remove www from HTTPS request in Nginx 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;
I have the following code:
server {
listen 443;
server_name domain.com;
ssl on;
ssl_certificate /etc/nginx/ssl/domain.com.crt;
ssl_certificate_key /etc/nginx/ssl/domain.com.key;
return 301 domain.com$request_uri; }
If I access domain.com everything works, if I access 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 domain.com with the valid cert.
But if I remove the ssl on; bit etc, then neither domain.com or 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 domain.com.
More posts by @Becky754
1 Comments
Sorted by latest first Latest Oldest Best
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 www.domain.com redirect to domain.com without SSL Invalid warning, your certificate must be valid to both domain.com and domain.com.
The simplest way is ask your CA to append 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 domain.com although it's pretty overkill.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.