I've created a new site, and purchased an EV cert for the site (www.mysite.com).
The cert is valid for WWW.mysite.com, however I know that several users are trying to get to the site via mysite.com (no WWW) - in which, the DNS name does resolve to the same host/IP.
In my config, if I listen for mysite.com on 443, without the SSL enabled, there's errors (because browser expects SSL). However if I put my cert there, or a self signed cert, the browser will throw an error saying it's an invalid site because of cert mismatch.
Is there any way in NGINX to rewrite the traffic from https://mynewsite.com to https://WWW.mynewsite.com without having to recreate the cert to include both DNS names?
#######################################
#### MYSITE.COM Server on Port 443 ####
#######################################
server {
###################################################################
##### Listen on Port:443, Listen for URL/Servername (without the WWW) #####
##### Auto rewrite the request to WWW.MYSITE.COM #####
###################################################################
listen 443;
server_name mysite.com;
rewrite ^(,*) https://www.mysite.com$1 permanent;
}
#############################################
#### WWW.MYSITE.COM SERVER on Port 443 ####
#############################################
server {
listen 443;
server_name www.mysite.com;
#########################################
##### SSL Enabling and Cert Declarations #####
#########################################
ssl on;
ssl_certificate /something/cert/mysite.crt;
ssl_certificate_key /something/cert/mysite.key;
location {
configs;
}
}
The cert is valid for WWW.mysite.com, however I know that several users are trying to get to the site via mysite.com (no WWW) - in which, the DNS name does resolve to the same host/IP.
In my config, if I listen for mysite.com on 443, without the SSL enabled, there's errors (because browser expects SSL). However if I put my cert there, or a self signed cert, the browser will throw an error saying it's an invalid site because of cert mismatch.
Is there any way in NGINX to rewrite the traffic from https://mynewsite.com to https://WWW.mynewsite.com without having to recreate the cert to include both DNS names?
#######################################
#### MYSITE.COM Server on Port 443 ####
#######################################
server {
###################################################################
##### Listen on Port:443, Listen for URL/Servername (without the WWW) #####
##### Auto rewrite the request to WWW.MYSITE.COM #####
###################################################################
listen 443;
server_name mysite.com;
rewrite ^(,*) https://www.mysite.com$1 permanent;
}
#############################################
#### WWW.MYSITE.COM SERVER on Port 443 ####
#############################################
server {
listen 443;
server_name www.mysite.com;
#########################################
##### SSL Enabling and Cert Declarations #####
#########################################
ssl on;
ssl_certificate /something/cert/mysite.crt;
ssl_certificate_key /something/cert/mysite.key;
location {
configs;
}
}