【问题标题】:Django: security middleware is crashing the siteDjango:安全中间件使网站崩溃
【发布时间】:2012-12-27 04:30:32
【问题描述】:

在生产中,我一直在尝试添加 djangosecure.middleware.SecurityMiddleware(来自 http://pypi.python.org/pypi/django-secure)to 我的设置,但没有任何运气让它工作。

当我跑步时:

./manage.py checksecure

一切顺利。但我无法加载网站。它给了我以下错误:

The webpage has resulted in too many redirects. Clearing your cookies for this site or 
allowing third-party cookies may fix the problem. If not, it is possibly a server 
configuration issue and not a problem with your computer.

在本地,当我使用生产设置时,我收到一个页面错误:

Unable to make a secure connection to the server. This may be a problem with the server,
or it may be requiring a client authentication certificate that you don't have.

然后我的终端充满了我无法破译的奇怪错误:

[12/Jan/2013 14:15:25] code 400, message Bad HTTP/0.9 request type    
('\x16\x03\x01\x00\x98\x01\x00\x00\x94\x03\x02P\xf1\xc4]\x97e\xdd\xdc\xa9\xeb\x0e\xfc\xbb\xfa3 ')
[12/Jan/2013 14:15:25] "??P??]?e?ܩ????3 Ʀ?-?:?.E:?o?FH?" 400 -
[12/Jan/2013 14:15:25] code 400, message Bad request syntax     ('\x16\x03\x01\x00\x98\x01\x00\x00\x94\x03\x02P\xf1\xc4]M\xeeA50\xfc\x15%\xc1\xa4\x02\xec\xf0\x1fO')
[12/Jan/2013 14:15:25] "??P??]M?A50?%????O" 400 -
[12/Jan/2013 14:15:25] code 400, message Bad request syntax ('\x16\x03\x01\x00\x98\x01\x00\x00\x94\x03\x01P\xf1\xc4]\x8eg\xbey\x155\xafiP5\x85r\xb4|\x8c\x

有什么建议吗?

【问题讨论】:

    标签: django ssl nginx django-settings django-middleware


    【解决方案1】:

    无限重定向意味着您已将SECURE_SSL_REDIRECT 设置为True,但在生产中,您的站点运行在 SSL 剥离代理服务器后面,因此 Django 无法判断该请求实际上已经是 SSL,因此它不断尝试重定向到 SSL。如链接文档中所述,您需要确定代理设置的标头以指示外部 SSL 请求,并相应地设置 SECURE_PROXY_SSL_HEADER 设置。

    在本地使用生产设置将不起作用,因为 Django 的开发服务器不支持 SSL。奇怪的终端输出是您的浏览器试图与不理解 SSL 的服务器进行 SSL 握手。

    【讨论】:

    • 谢谢你
    猜你喜欢
    • 2015-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多