I have 2 websites (old-domain.com and new-domain.com), I am a shutting old-domain.com down and what to redirect to the new-domain. So I added the rewrite and return lines into my conf files. The catch all (return 301 *) works without a warning, however when I go to a specific page (e.g. old-domain.com/page-1), I get a certificate warning:
This server could not prove that it is old-domain.com; its security certificate is from new-domain.com. This may be caused by a misconfiguration or an attacker intercepting your connection.
Both domains are on the same IP, below is my nginx setup:
new-domain.conf:
server {
listen 80;
server_name new-domain.com;
}
server {
listen 433;
server_name new-domain.com;
ssl_certificate new-domain.cert;
ssl_certificate_key new-domain.cert_key;
ssl_client_certificate new-domain.client_cert_key;
}
old-domain.conf:
server {
listen 80;
listen 433;
server_name old-domain.com;
ssl_certificate old-domain.cert;
ssl_certificate_key old-domain.cert_key;
ssl_client_certificate old-domain.client_cert_key;
#catch all - works, but causes invalid certificate
rewrite ^/page-1 https://new-domain.com/differnt-path/page-1-extra permanent;
#catch all - works without warning
return 301 https://new-domain.com;