我需要 nginx 将所有 http URL 重定向到 https,但“.secret/”目录除外,该目录应继续用作 http。
因此,例如:
http://example.com/a.html --> https://example.com/a.htmlhttp://example.org/z/b.html --> https://example.org/z/b.htmlhttp://example.com/.secret/x.html --> http://example.com/.secret/x.html我的配置中有以下内容,但对于 http,它返回包含“_”的地址。
server {
listen 80;
server_name _;
location /.secret {
return http://$server_name$request_uri;
}
location / {
return 301 https://$server_name$request_uri;
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
更新:
结合@mforsetti 和@Pothi_Kalimuthu 的评论,以下内容有效:
server {
listen 80;
server_name _;
location /.secret { }
location / {
return 301 https://$host$request_uri;
}
}
Run Code Online (Sandbox Code Playgroud)