Standard nginx redirect:
server { listen 80; listen 443 ssl; server_name up-eleven.de www.domain-a.tld; return 301 https://www.domain-b.tld; }
Produces browser ssl errors (wrong cert) cs before executing the redirecting order the https connection is established between your browser and the orig domain.
Solution: Run certbot on the orig domain you redirect from:
certbot --nginx -d domain-a.tld -d www.domain-a.tld
The bot inserts this new cert into the nginx conf related to the virtual domain like:
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/domain-a.tld/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain-a.tld/privkey.pem; # managed by Certbot
server_name domain-a.tld www.domain-a.tld;
return 301 https://www.domain-b.tld;
}
server {
if ($host = www.domain-a.tld) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = domain-a.tld) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name domain-a.tld www.domain-a.tld;
#return 404; # managed by Certbot
return 301 https://www.domain-b.tld;
}
I did replace the last line (return 404; # managed by Certbot) written by certbot by my own stuff (return 301 https://www.domain-b.tld;)