我试图用SSL在本地测试我的Django应用程序。我对@login_required
装饰者有一个看法。所以当我点击/locker
时,我被重定向到/locker/login?next=/locker
。这与http正常工作。Django @login_required丢弃https
但是,每当我使用HTTPS,重定向莫名其妙地下降了安全连接,所以我得到的东西像https://cumulus.dev/locker -> http://cumulus.dev/locker/login?next=/locker
如果我直接去https://cumulus.dev/locker/login?next=locker
页面打开罚款通过安全连接。但是一旦我输入用户名和密码,我就回到http://cumulus.dev/locker
。
我使用Nginx来处理SSL,然后与runserver
交谈。我的nginx的配置是
upstream app_server_djangoapp {
server localhost:8000 fail_timeout=0;
}
server {
listen 80;
server_name cumulus.dev;
access_log /var/log/nginx/cumulus-dev-access.log;
error_log /var/log/nginx/cumulus-dev-error.log info;
keepalive_timeout 5;
# path for static files
root /home/gaurav/www/Cumulus/cumulus_lightbox/static;
location/{
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server_djangoapp;
break;
}
}
}
server {
listen 443;
server_name cumulus.dev;
ssl on;
ssl_certificate /etc/ssl/cacert-cumulus.pem;
ssl_certificate_key /etc/ssl/privkey.pem;
access_log /var/log/nginx/cumulus-dev-access.log;
error_log /var/log/nginx/cumulus-dev-error.log info;
keepalive_timeout 5;
# path for static files
root /home/gaurav/www/Cumulus/cumulus_lightbox/static;
location/{
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server_djangoapp;
break;
}
}
}
我要说,“哦,只是改变'settings.py'文件中的'LOGIN_URL'”...但我试过了,它不起作用。好问题。 – 2012-07-20 02:19:35