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

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

本文介绍了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;

位置/ {
#主机和端口到fastcgi服务器
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授权;
fastcgi_intercept_errors关闭;
}
}
}

我启动Django FastCGI进程with:

  python /home/webapp/manage.py runfcgi method = threaded host = 127.0.0.1 port = 8801 pidfile = / home / webapp / fastcgi.pid 


解决方案

确保nginx是发送 fastcgi_param HTTPS on 用于443上的连接。


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 (request.is_secure() == False). However, SSL is setup correctly, and I've verified my https:// urls are secure with an SSL checker.

How can I get Django to correctly detect when the request is from an HTTPS url?

My Nginx settings are:

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

I start the Django FastCGI process with:

python /home/webapp/manage.py runfcgi method=threaded host=127.0.0.1 port=8801 pidfile=/home/webapp/fastcgi.pid
解决方案

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

这篇关于NGINX后面的FastCGI应用程序无法检测到使用HTTPS安全连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 17:42