【问题标题】:Force https for single directory on my server with nginx config使用 nginx 配置为我的服务器上的单个目录强制 https
【发布时间】:2017-04-14 21:48:21
【问题描述】:

我试图通过在我的 nginx 配置文件中放置一个重写规则来强制我服务器上的单个子目录使用 SSL。

因此,例如,当用户访问 example.com/billing 或 example.com/billing/user 时,他们会被带到 https://example.com/billinghttps://example.com/billing/user

我安装了 SSL 证书等。这是我的服务器块中用于 nginx 的规则:

#billing location
location /billing/ {
    if (!-e $request_filename){
        rewrite ^/billing/(.*)$ /billing/index.php?request=$1 last;
    }
}

有没有办法可以修改此规则以包括强制 https?

【问题讨论】:

    标签: ssl nginx https nginx-location


    【解决方案1】:

    我希望你有两个服务器块,一个用于 http,另一个用于 http SSL 连接;在您的 http 服务器块中添加重定向到 https 内 /billing/ 位置块将解决问题。

    server {
     listen 80;
     location /billing/ {
       # 301 for permanent redirect
       return 301 https://$host$request_uri;
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 2020-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-20
      相关资源
      最近更新 更多