我试图通过在我的 nginx 配置文件中放置重写规则来为我服务器上的单个子目录强制使用 SSL。
因此,例如,当用户访问 example.com/billing 或 example.com/billing/user 时,他们将被带到 https://example.com/billing或 https://example.com/billing/user .
我安装了 SSL 证书等。这是我的 nginx 服务器 block 中的规则:
#billing location
location /billing/ {
if (!-e $request_filename){
rewrite ^/billing/(.*)$ /billing/index.php?request=$1 last;
}
}
有没有办法修改此规则以包括强制 https?
最佳答案
我希望你有两个服务器 block ,一个用于http,另一个用于http SSL 连接;在您的 http 服务器 block 中,在 /billing/
位置 block 中添加到 https 的重定向将解决问题。
server {
listen 80;
location /billing/ {
# 301 for permanent redirect
return 301 https://$host$request_uri;
}
}
关于ssl - 使用 nginx 配置为我的服务器上的单个目录强制使用 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43419679/