django – NGINX后面的FastCGI应用程序无法检测到使用HTTPS安全连接 - 代码日志

django – NGINX后面的FastCGI应用程序无法检测到使用HTTPS安全连接

我在Nginx后面运行FastCGI,需要检测何时通过HTTPS访问url。但是,我的Django Web应用程序总是报告连接是HTTP(request.is_secure()== False)。但是,SSL设置正确,我已经验证我的https:// urls是安全的SSL检查器。

如何让Django正确检测请求是从HTTPS网址?

我的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 
确保nginx为443上的连接发送fastcgi_param HTTPS。
http://stackoverflow.com/questions/4848438/fastcgi-application-behind-nginx-is-unable-to-detect-that-https-secure-connectio

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:django – NGINX后面的FastCGI应用程序无法检测到使用HTTPS安全连接