姜戈 + uwsgi + nginx + SSL协议
我在 DotCloud 上使用 Django,它在 uwsgi + nginx 之上使用 Django。我正在尝试将所有 http 流量重定向到 https,这会导致重定向循环。我正在使用以下 http 配置
if ($http_x_forwarded_port != 443) { rewrite ^ https://$http_host/; }
Django 似乎不明白它是在 https 上运行的,并且标头未保留。它将 https://url.com/ 重定向到 http ://url.com/accounts/login/ 一次又一次地重定向,导致重定向循环。我并不是真正的 nginx 专家,对它的理解也不够深入。我可能做错了什么?
简而言之,如何在 uswsgi 和 nginx 之上运行的 django 中运行将 http 重定向到 https。
I am using Django on DotCloud which uses Django on top of uwsgi + nginx. I am trying to redirect all http traffic to https which is leading to a redirect loop. I am using the following http configuration
if ($http_x_forwarded_port != 443) { rewrite ^ https://$http_host/; }
It seems that Django doesn't understand that it is operating on https and the header is not preserved. It redirects https://url.com/ to http://url.com/accounts/login/ which is redirecting again and again leading to a redirect loop. I am not really an expert in nginx and do not understand it well enough. What can I be doing wrong?
In short how do I run redirect http to https in django running on top of uswsgi and nginx.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我需要更多的信息来让 Django 意识到它应该使用 https。
在 settings.py 中我添加了
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
并在 nginx 配置中
I needed a bit more to make Django aware that it should be using https.
In settings.py I added
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
And in the nginx configuration
在 nginx 配置中使用“if”是一个非常糟糕的主意!
Using "if" in nginx config is a very bad idea!