nginx配置http强制跳转https

leo 09月16日 180

顶级域名处理方法

把不带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.     }
 
 
看过的人 (3)
  • 23948098
  • Mr.Chen????????
  • admin
最新回复 (10)
返回