0

nginx配置http强制跳转https

xqx42rtxy
2023-2-26 365

顶级域名处理方法

把不带www.的域名301跳转,比如http://xxx.com

if ($host !~ www.xxxx.com){
         return 301 https://www.$host$request_uri;
    }

接下来还要处理http://www.xxx.com这种网址

 if ($server_port !~ 443){
        return 301 https://$host$request_uri;
    }

或者

if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }

二级域名处理方法
把不包含www的二级域名301到https,比如bbs.xxx.com

if ($server_port !~ 443){
        return 301 https://$host$request_uri;
    }

或者

 if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
最新回复 (0)

    暂无评论

请先登录后发表评论!

返回