我想在本地测试我的Django应用程序使用SSL。 我与一个视图@login_required
装饰。 所以,当我打/locker
,我重定向到/locker/login?next=/locker
。 这工作得很好则是http。
但是,每当我使用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;
}
}
}