# http强制跳转https
server
{
listen 80;
server_name www.lzskyline.com lzskyline.com;
# request_uri 取原始请求地址, uri 处理后的请求地址(不带参数、URL解码)
return 301 https://www.lzskyline.com$request_uri;
}
# 域名不带www强制跳到带www
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name www.lzskyline.com lzskyline.com;
# 也可以新增一个server监听443, 绑定域名lzskyline, 用return 301的方式跳转到这里
if ($http_host !~ "^www.lzskyline.com") {
# permanent = 301 永久跳, redirect = 302 临时跳(spam风险)
rewrite /.* https://www.lzskyline.com$request_uri permanent;
}
}
© 允许规范转载