nginx配置http强制跳转https
xiunoa 2020-8-23


顶级域名处理方法

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

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

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

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

或者

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

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

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

或者

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


最新回复 (0)
全部楼主
返回