FastCGI application behind NGINX is unable to detect that HTTPS secure connection is used

前端 未结 2 365
感情败类
感情败类 2020-12-24 15:21

I\'m running FastCGI behind Nginx, and need to detect when the url is accessed via HTTPS. However, my Django web application always reports that the connection is HTTP (req

相关标签:
2条回答
  • 2020-12-24 15:51

    Make sure nginx is sending fastcgi_param HTTPS on for connections on 443.

    0 讨论(0)
  • 2020-12-24 15:51

    Thanks to Yuji for the answer. I've updated my server block to conditionally inject HTTPS on or HTTPS off, depending on $server_port:

    {

    server {
        listen       80;
        listen       443 default ssl;
    
        if ($server_port = 443) { set $https on; }
        if ($server_port = 80) { set $https off; }
    
        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;
    
           fastcgi_param HTTPS $https;
        }
    }
    

    }

    0 讨论(0)
提交回复
热议问题