I've got two domains both with SSL certs on one nginx instance. I'm trying to redirect http to https and removing www hostname on both domains i.e. http://www.site1.com redirects to https://site1.com
What I've got at the moment, http://site1.com redirects fine and issues the correct cert, however http://www.site1.com issues the SSL cert from site2.com and doesn't redirect without www. site2 works fine for all redirects and issues teh correct certs. I think it has to do with me using "default" in the SSL config for site2, however if I remove it both sites then return connection refused errors.
Here's the configs
/etc/nginx/sites-available/site1
upstream site1.com {
server unix:/home/site1.com/site1.com.sock;
}
server {
listen 80;
server_name site1.com www.site1.com;
return 301 https://site1.com$request_uri;
}
server {
listen 443 ssl;
server_name www.site1.com;
return 301 https://site1.com$request_uri;
}
server {
listen 80;
server_name site1.com;
# SSL configuration
listen 443 ssl http2;
listen [::]:443 ssl http2;
include snippets/ssl-site1.com.conf;
/etc/nginx/sites-available/site2
upstream site2 {
server unix:/home/site2/site2.sock;
}
server {
listen 80;
server_name site2.com www.site2.com site2.co.uk www.site2.co.uk;
return 301 https://site2.com$request_uri;
}
server {
listen 443 ssl;
server_name www.site2.com;
return 301 https://site2.com$request_uri;
}
server {
listen 80;
server_name site2.com;
# SSL configuration
listen 443 ssl default http2;
listen [::]:443 ssl default http2;
include snippets/ssl-site2.com.conf;
include snippets/ssl-params.conf;
http://www.site1.com
does not issue any certificate since it is only a HTTP connection. Did you meanhttps://www.site1.com
? What is the CURL output of the request tohttp://www.site1.com
andhttps://site1.com
?http://www.site1.com
to redirect tohttps://site1.com
. Curl tohttp://www.site1.com
is301 moved permanently
and curl tohttps://site1.com
returns the page and cert correctlyhttps://www.site1.com
returnscurl: (51) SSL: certificate subject name (site2.com) does not match target host name 'www.site1.com'