#default:
server {
listen 80 default_server;
server_name _;
return 404;
}
server {
listen 443 default_server;
server_name _;
ssl_certificate /etc/nginx/ssl/dummy.crt;
ssl_certificate_key /etc/nginx/ssl/dummy.key;
return 404;
}
#old-domain:
server {
listen 80;
server_name old-domain.com;
server_name www.old-domain.com;
return 301 https://www.old-domain.com$request_uri;
}
server {
listen 443;
server_name old-domain.com;
server_name www.old-domain.com;
ssl_certificate /etc/nginx/ssl/old-domain.crt;
ssl_certificate_key /etc/nginx/ssl/old-domain.key;
#catch all
return 301 https://new-domain.com;
}
#new-domain:
server {
listen 80;
server_name new-domain.com;
server_name www.new-domain.com;
return 301 https://www.new-domain.com$request_uri;
}
server {
listen 443;
server_name new-domain.com;
server_name www.new-domain.com;
ssl_certificate /etc/nginx/ssl/new-domain.crt;
ssl_certificate_key /etc/nginx/ssl/new-domain.key;
....
}
As, requested, here is the output of curl -I for the various requests:
curl -I http://old.domain.com
HTTP/1.1 301 Moved Permanently Server: nginx/1.16.1 Date: Mon, 11 Nov 2019 07:48:57 GMT Content-Type: text/html Content-Length: 169 Connection: keep-alive Location: https://www.old.domain.com/
curl -I https://old.domain.com
curl: (60) SSL certificate problem: self signed certificate More details here: https://curl.haxx.se/docs/sslcerts.html curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above.