I have just purchased a Wildcard SSL certificate that allows me to have access to dynamic sub-domains. I can access the following domains fine with my config:
http://example.co/ goes to -> https://example.co/
So I'm forcing all HTTP to HTTPS and removing the www
.
My problem is that I have dynamic sub-domains which allow users to have any sub-domain they want (https://user1.example.co, https://user2.example.co, https://user3.example.co).
My problem is when a user visits http://www.user1.example.co/ or https://www.user1.example.co/ I get the following:
NET::ERR_CERT_COMMON_NAME_INVALID
My config:
server {
server_name www.example.co;
return 301 $scheme://example.co$request_uri;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/nginx/blah;
ssl_certificate_key /etc/nginx/blah;
server_name example.co *.example.co;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header X_FORWARDED_PROTO https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Url-Scheme $scheme;
proxy_redirect off;
proxy_max_temp_file_size 0;
}
}
I've removed the certificate and the logic inside but my goal is to have any www.
removed. So it would like so:
http://www.user1.example.com -> https://user1.example.com http://www.user2.example.com -> https://user2.example.com
And of course all my domains above work like they are now.