admin管理员组

文章数量:1642331

Nginx 强制调整到https

在配置文件中增加代码

 if ($server_port !~ 443){  # 如果不是443端口,强制调整到https
        rewrite ^(/.*)$ https://$host$1 permanent;
    }

Nginx 排除一些目录不跳转到https

上面的代码是将全站的http访问重定向到https,如果网站的某些目录需要http访问(这些目录不能强制https),需要采用下面代码

    if ($server_port = 80) { # 80端口需要跳转
      set $jump "t";
    }
    if ($request_uri ~ "/dir1"){ # /dir1 开头的目录可以不使用https
      set $jump "f";
    }
    if ($request_uri ~ "/dir2"){ # /dir2 开头的目录可以不使用https
      set $jump "f";
    }
    if ($jump = "t"){
     rewrite ^(/.*)$  https://$host$1 permanent;
    }

本文标签: 跳转到目录NginxhttpHTTPS