大网数据广告活动
服务器运维问答

nginx redirecting domains with ssl

· 52CE 我爱测

I have a new domain (my-future-domain.com) that I am trying to use to replace my current domain (my-current-domain.com). I am using a DigitalOcean Nginx server on Ubuntu and believe that I should be taking the following steps in …

问题原文

原帖链接 · cphill · CC BY-SA 3.0

I have a new domain (my-future-domain.com) that I am trying to use to replace my current domain (my-current-domain.com). I am using a DigitalOcean Nginx server on Ubuntu and believe that I should be taking the following steps in order to replace the current domain with my new domain, but I have never dealt with domain migrations before which is why I would like feedback on the steps I plan to take.

1) Point A record to IP associated with current server and CNAME to A record

A = my-future-domain.com directs to 100.200.1.90

CNAME = www.my-future-domain.com is an alias of my-future-domain.com

2) use certbot to generate SSL for my-future-domain.com and www.my-future-domain.com sudo certbot --nginx -d my-future-domain.com -d www.my-future-domain.com

3) Select 2: Redirect - Make all requests redirect to secure HTTPS access. at certbot prompt

4) Add new server_name block for new domain name and mimic the current server block

Current Block:

#This server block will redirect http:// to https://www.my-current-domain.com
server {
    listen 80;
    listen [::]:80;
    server_name my-current-domain.com www.my-current-domain.com;
    return 301 https://www.my-current-domain.com$request_uri;
}

#This server block will redirect https://my-current-domain.com to https://www.my-current-domain.com (expecting that you have a certificate for my-current-domain.com as well as www.my-current-domain.com
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    include snippets/ssl-www.my-current-domain.com.conf;
    include snippets/ssl-params.conf;
    server_name my-current-domain.com;
    return 301 https://www.$server_name$request_uri;
}

New Website Block:

#This server block will redirect http:// to https://www.my-future-domain.com
server {
    listen 80;
    listen [::]:80;
    server_name my-future-domain.com www.my-future-domain.com;
    return 301 https://www.my-future-domain.com$request_uri;
}

#This server block will redirect https://my-future-domain.com to https://www.my-future-domain.com (expecting that you have a certificate for my-future-domain.com as well as www.my-future-domain.com
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    include snippets/ssl-www.my-future-domain.com.conf;
    include snippets/ssl-params.conf;
    server_name my-future-domain.com;
    return 301 https://www.$server_name$request_uri;
}

5) Redirect traffic from my-current-domain.com and www.my-current-domain.com to www.my-future-domain.com. Do I update "Current Block" from step 4?

6) Remove A and CNAME record for my-current-domain.com

Is there anything I might be missing?

已采纳解答

原帖链接 · T H Wright · CC BY-SA 3.0

The DNS looks proper. To simplify the DNS requests, you could make my-current-domain.com also set up as a CNAME to www.my-future-domain.com, not just www.my-current-domain.com. You wouldn't need to remove the DNS until the old domain expires; it is harmless to leave it in place. (It would also benefit anything that is still referencing the old domain by having it in place. The redirects should handle the rest.)

I would configure your server blocks as follows.

server {
        listen 80;
        listen [::]:80;
        server_name my-future-domain.com www.my-future-domain.com my-current-domain.com www.my-current-domain.com;
        return 301 https://www.my-future-domain.com$request_uri;
}

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name www.my-future-domain.com;
        …

You can clean up the code by combining the two server blocks.

If you pursue your current plan, if someone requested http://my-current-domain.com, they would be redirected to https://www.my-current-domain.com and then redirected again to https://www.my-future-domain.com. You can save on a redirect by having this all performed in the initial server block.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-03-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。