0
#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.

3
  • I have added a more detailed example of my config. Nov 11, 2019 at 0:19
  • Welcome to ServerFault. Please post an example curl request on what's happening and what's expected to happen. Nov 11, 2019 at 1:23
  • I have added the curl output to the original question. Nov 11, 2019 at 7:53

1 Answer 1

0

I think that the problem it's with the certificates. You need to add the ssl proper certificate to the server block that you are redirecting on the old domain. Make sure that the certificate on the old domain is correct or it won't work

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .