Redirect all requests for an old domain to a new domain. For SEO purposes this redirect should be Permanent (301).

Redirect Preserving Protocol

Redirect all requests for an old domain to a new domain, preserving the original protocol used, by adding the following to your nginx.conf file:

server {
    listen 80;
    server_name www.old-domain.com;
    return 301 $scheme://www.new-domain.com$request_uri;
}

With the above rule, if the original request was made using HTTP protocol, the redirected request will be HTTP as well. Same goes for HTTPS to HTTPS.

Redirect Forcing HTTPS Protocol

Redirect all requests for an old domain to a new domain, forcing the forwarded request to HTTPS protocol, by adding the following to your nginx.conf file:

server {
    listen 80;
    server_name www.old-domain.com;
    return 301 https://www.new-domain.com$request_uri;
}

All requests will be forwarded to the new domain using HTTPS.