gpt4 book ai didi

django - 当下游处理 ssl 时,Nginx 在同一 server_name block 上从 http 重写为 https

转载 作者:太空宇宙 更新时间:2023-11-03 14:06:42 24 4
gpt4 key购买 nike

我们已经有这个问题很久了,它开始咬我们的屁股。我们在 django 框架上为用 python 编写的客户端运行一个站点。然后我们使用 nginx 作为 django 的网络服务器/代理。这通常是最标准的设置并且运行良好。

问题是我们的客户端有另一个更高的 apache 服务器。该服务器处理 ssl 终止并仅通过普通 http 将请求传递给我们。 apache 服务器接受 2 个域名上的 http 和 https。

我们可以很容易地在 nginx 级别将 http 重写为 https,但问题在于用户可以删除 https 并只使用 http。

有没有办法在 nginx 级别强制用户返回 https://secure.example.com如果他们在 http://secure.example.com .

谢谢

最佳答案

通常的技术是为处理 ssl 终止的代理添加 X-Forwarded-Proto header 。然后,上游应用程序可以在进入安全区域时有条件地重定向。

使用 nginx 这可以使用 map 来完成:

map $http_x_forwarded_proto $insecure {
default 1;
https 0;
}

server {
...
if ($insecure) {
return 301 https://$host$request_uri;
}
...
}

关于django - 当下游处理 ssl 时,Nginx 在同一 server_name block 上从 http 重写为 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39972513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com