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

前端 未结 2 364
感情败类
感情败类 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

    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;
        }
    }
    

    }

提交回复
热议问题