我在Nginx後面運行FastCGI,並且需要檢測何時通過HTTPS訪問url。但是,我的Django Web應用程序總是報告連接是HTTP(request.is_secure()== False)。但是,SSL設置正確,並且我已通過SSL檢查器驗證了我的https://網址是否安全。NGINX後面的FastCGI應用程序無法檢測到使用HTTPS安全連接
我該如何讓Django正確檢測請求來自HTTPS url?
我的Nginx的設置是:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
listen 443 default ssl;
ssl_certificate /home/webapp/ssl.crt
ssl_certificate_key /home/webapp/ssl.key
server_name myapp.com;
access_log /home/webapp/access.log
error_log /home/webapp/error.log
root /home/mywebapp;
location/{
# host and port to fastcgi server
fastcgi_pass 127.0.0.1:8801;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
}
}
我開始Django的FastCGI進程:
python /home/webapp/manage.py runfcgi method=threaded host=127.0.0.1 port=8801 pidfile=/home/webapp/fastcgi.pid
啊,謝謝,那做的伎倆。有沒有辦法只爲端口443設置這個參數?也就是說,無需複製整個配置塊? – 2011-01-31 19:07:42
如下所示...您應該將變量設置爲「關閉」80端口。 – 2014-01-04 16:15:00