说明 根据以下两种情况,选择符合自己的配置 没有配置SSL证书 server { listen 80; #填写绑定证书的域名 server_name ochaly.com; return 301 http://www.ochaly.com$request_uri; } server { listen 80; #填写绑定证书的域名 server_name www.ochaly.com; location / { # 网站主页路径 root html; index index.html index.htm; } } 配置了SSL证书 修改监听443端口的server配置,在location配置前面加上: if ($host != 'www.ochaly.com') { rewrite ^/(.*)$ https://www.ochaly.com/$1 permanent; } 重启Nginx ./nginx -s reload
评论区