我正在将ssl添加到django应用程序的过程中,并且遇到了一些问题,我的链接从https重定向到http。
最终,我会让nginx将所有http请求重定向到https,但目前我同时允许这两个请求。
所以,如果你去https://www.mysite.com,一切都很好。但是,单击“关于链接”:href='/about‘会将您重定向到http://www.mysite.com/about。
About是一个超基本(静态)页面。下面是urls.py中的条目:
(r'^about/$', 'search.views.about'),下面是view函数:
def about(request):
return render_to_response('search/about.html')django不应该将我的用户定向到https://www.mysite.com/about/吗?我相信这与request.is_secure()方法有关。它总是为我返回false。我读到我需要设置os.environ‘’HTTPS‘= "on“才能返回true。我该怎么做呢?还有什么我需要做的吗?我是不是应该把https硬编码到我所有的链接中?
谢谢你的帮助。
发布于 2012-09-07 09:02:05
原来我使用的nginx代码把一切都搞砸了。而不是:
if ($http_x_forwarded_port != 443) { rewrite ^ https://$http_host/; }使用:
if ($http_x_forwarded_port != 443) { rewrite ^(.*) https://$host$1 permanent; 来进行重定向。因为第一个丢弃了除主机之外的所有内容。
https://stackoverflow.com/questions/12309952
复制相似问题