在制作时,我一直在尝试添加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
有什么建议吗?
答案 0 :(得分:6)
无限重定向意味着您已将SECURE_SSL_REDIRECT设置为True
,但在生产中您的站点在SSL剥离代理服务器后面运行,因此Django无法确定该请求实际上已经是SSL ,所以它不断尝试重定向到SSL。如链接文档中所述,您需要确定代理设置的标头以指示外部SSL请求,并相应地设置SECURE_PROXY_SSL_HEADER设置。
在本地使用生产设置将无法正常工作,因为Django的开发服务器不支持SSL。奇怪的终端输出是您的浏览器尝试与不了解SSL的服务器进行SSL握手。