【问题标题】:Django infinity redirect in IIS behind a proxy server turned on SSL代理服务器后面的 IIS 中的 Django 无限重定向打开了 SSL
【发布时间】:2020-01-06 22:47:03
【问题描述】:

在 Windows Server 上部署时,我遇到了 Python Django 的问题。 总结一下我的情况:

最终用户 代理服务器将SSL Win Server上的Django

End-User 与 Proxy server 之间的通信是 HTTPS,Proxy Server 与 Django 之间的通信是 HTTP。

所以,当用户浏览网站时,代理服务器尝试重定向到 https 并传递给 Django,Django 处理请求并将 http 返回给代理,代理服务器尝试将其重定向到 https => 导致 CSRF 失败=> 在这里循环无穷大。

我在这里阅读了 django 文档https://docs.djangoproject.com/en/2.2/ref/settings/#secure-proxy-ssl-header

Warning

Modifying this setting can compromise your site’s security. Ensure you fully understand your setup before changing it.

Make sure ALL of the following are true before setting this (assuming the values from the example above):

- Your Django app is behind a proxy.
- Your proxy strips the X-Forwarded-Proto header from all incoming requests. In other words, if end users include that header in their requests, the proxy will discard it.
- Your proxy sets the X-Forwarded-Proto header and sends it to Django, but only for requests that originally come in via HTTPS.
If any of those are not true, you should keep this setting set to None and find another way of determining HTTPS, perhaps via custom middleware.

=> 我的 Django 应用在代理后面,传入的请求来自 https,所以我已经应用了设置:

SECURE_SSL_REDIRECT = True
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

但它仍然是无限重定向。

所以有人有同样的问题,请给我一些想法?

【问题讨论】:

  • 您能发布您的 IIS 代理配置吗?因为它还需要 IIS 服务器添加自定义请求标头 HTTP_X_FORWARDED_PROTO。你是用 httpmodule 实现的吗?
  • 谢谢,但我无权访问此代理服务器 :(

标签: django redirect iis


【解决方案1】:

似乎没有人像我一样遇到这个问题,所以我决定使用带有 IIS 的 Apache httpd 作为代理来切换到另一种解决方案。 详细的供大家参考,以后会更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    • 2018-08-23
    • 2019-08-03
    • 1970-01-01
    • 2016-11-13
    相关资源
    最近更新 更多