Nginx强制跳转HTTS但跳过指定目录
2021-05-31 / Server / 1365 次围观 / 0 次吐槽 /默认Nginx开启强制跳转https后的配置文件是如下代码
if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; }
可以用以下代码替换掉上面的代码即可;
set $flag 0; if ($server_port !~ 443) { set $flag "${flag}1"; } if ($request_uri !~ "/directory/"){ //这里可以改成指定的目录或文件 set $flag "${flag}2"; } if ($flag = "012"){ rewrite ^(.*)$ https://$host$1 permanent; }
Powered By Cheug's Blog
Copyright Cheug Rights Reserved.