Nginx重定向 http跳https & 域名跳www

# 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;
        }
    }

博客文章迁移: 2019-10-13 18:38

你可能感兴趣的:(Nginx重定向 http跳https & 域名跳www)