在 CentOS 上“换域名”通常分几种场景,下面按最常见情况给你说明,你可以对号入座。
如果只是想让 hostname 变成新域名(比如 web.example.com):
hostnamectl set-hostname web.example.com
确认:
hostname
修改 /etc/hosts(可选但建议):
vi /etc/hosts
添加或改成:
127.0.0.1 web.example.com
编辑站点配置:
vi /etc/nginx/conf.d/your-site.conf
把:
server_name old.com www.old.com;
改成:
server_name new.com www.new.com;
检查并重载:
nginx -t
systemctl reload nginx
vi /etc/httpd/conf.d/your-site.conf
修改:
ServerName new.com
ServerAlias www.new.com
重载:
systemctl reload httpd
服务器改了没用,必须去域名服务商后台:
new.com 的 A 记录指向 CentOS 服务器 IPwww.new.com 也指向同一 IP换域名后证书必须重新申请:
certbot --nginx -d new.com -d www.new.com
我可以给你精确命令。