Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
难以让SSL与django+;nginx+;wsgi_Ssl_Nginx_Mod Wsgi - Fatal编程技术网

难以让SSL与django+;nginx+;wsgi

难以让SSL与django+;nginx+;wsgi,ssl,nginx,mod-wsgi,Ssl,Nginx,Mod Wsgi,我已经介绍了Django+nginx+wsgi+ssl的几个示例,但我无法让它们正常工作。我只是在浏览器中遇到一个错误,无法连接 我正在主机上运行两个网站。除了ip地址、服务器名称和目录之外,配置文件是相同的 当两者都不使用SSL时,它们工作正常。当我试着用其中一个收听443时,我也无法连接到任何一个 我的配置文件如下,如有任何建议,将不胜感激 server{ listen xxx.xxx.xxx.xxx:80; server_name sub.domain.com; access_log /

我已经介绍了Django+nginx+wsgi+ssl的几个示例,但我无法让它们正常工作。我只是在浏览器中遇到一个错误,无法连接

我正在主机上运行两个网站。除了ip地址、服务器名称和目录之外,配置文件是相同的

当两者都不使用SSL时,它们工作正常。当我试着用其中一个收听443时,我也无法连接到任何一个

我的配置文件如下,如有任何建议,将不胜感激

server{
listen xxx.xxx.xxx.xxx:80;
server_name sub.domain.com;

access_log /home/django/logs/nginx_customerdb_http_access.log;
error_log /home/django/logs/nginx_customerdb_http_error.log;

location / { 
    proxy_pass  http://127.0.0.1:8080; 
    proxy_redirect          off;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size    10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout   90; 
    proxy_send_timeout      90; 
    proxy_read_timeout      90; 
    proxy_buffers           32 4k; 
}   

location /site_media/ {
    alias /home/django/customerdb_site_media/;
}   

location /admin-media/ {
    alias /home/django/django_admin_media/;
}   
}

server{
listen xxx.xxx.xxx.xxx:443;
server_name sub.domain.com;

access_log /home/django/logs/nginx_customerdb_http_access.log;
error_log /home/django/logs/nginx_customerdb_http_error.log;

ssl on; 
ssl_certificate sub.domain.com.crt;
ssl_certificate_key sub.domain.com.key;
ssl_prefer_server_ciphers   on; 


location / { 
    proxy_pass              http://127.0.0.1:8080; 
    proxy_redirect          off;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Protocol    https;
    client_max_body_size    10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout   90;
    proxy_send_timeout      90;
    proxy_read_timeout      90;
    proxy_buffers           32 4k;
}

location /site_media/ {
    alias /home/django/customerdb_site_media/;
}

location /admin-media/ {
    alias /home/django/django_admin_media/;
}
}


<VirtualHost *:8080>
ServerName xxx.xxx.xxx.xxx
ServerAlias xxx.xxx.xxx.xxx

LogLevel warn
ErrorLog /home/django/logs/apache_customerdb_error.log
CustomLog /home/django/logs/apache_customerdb_access.log combined

WSGIScriptAlias / /home/django/customerdb/apache/django.wsgi
WSGIDaemonProcess customerdb_wsgi processes=4 threads=5
WSGIProcessGroup customerdb_wsgi

SetEnvIf X-Forwarded-Protocol "^https$" HTTPS=on

</VirtualHost>
服务器{
听xxx.xxx.xxx.xxx:80;
服务器名称sub.domain.com;
access_log/home/django/logs/nginx_customerdb_http_access.log;
error\u log/home/django/logs/nginx\u customerdb\u http\u error.log;
位置/{
代理通行证http://127.0.0.1:8080; 
代理_重定向关闭;
代理设置头主机$Host;
代理集头X-Real-IP$remote\u addr;
proxy\u set\u header X-Forwarded-For$proxy\u add\u X\u Forwarded\u For;
客户最大身体尺寸10米;
客户端\主体\缓冲区\大小128k;
代理连接超时90;
代理发送超时90;
代理读取超时90;
代理缓存324k;
}   
地点/地点\媒体/{
别名/home/django/customerdb_site_media/;
}   
位置/管理媒体/{
别名/home/django/django_admin_media/;
}   
}
服务器{
听xxx.xxx.xxx.xxx:443;
服务器名称sub.domain.com;
access_log/home/django/logs/nginx_customerdb_http_access.log;
error\u log/home/django/logs/nginx\u customerdb\u http\u error.log;
ssl-on;
ssl_certificate sub.domain.com.crt;
ssl_证书_密钥sub.domain.com.key;
ssl首选服务器上的密码;
位置/{
代理通行证http://127.0.0.1:8080; 
代理_重定向关闭;
代理设置头主机$Host;
代理集头X-Real-IP$remote\u addr;
proxy\u set\u header X-Forwarded-For$proxy\u add\u X\u Forwarded\u For;
代理集头X转发协议https;
客户最大身体尺寸10米;
客户端\主体\缓冲区\大小128k;
代理连接超时90;
代理发送超时90;
代理读取超时90;
代理缓存324k;
}
地点/地点\媒体/{
别名/home/django/customerdb_site_media/;
}
位置/管理媒体/{
别名/home/django/django_admin_media/;
}
}
服务器名xxx.xxx.xxx.xxx
服务器别名xxx.xxx.xxx.xxx
日志级别警告
ErrorLog/home/django/logs/apache_customerdb_error.log
CustomLog/home/django/logs/apache_customerdb_access.log组合
WSGIScriptAlias//home/django/customerdb/apache/django.wsgi
WSGIDaemonProcess customerdb_wsgi进程=4个线程=5个
WSGIProcessGroup customerdb_wsgi
setenif X-Forwarded-Protocol“^https$”https=on

UDPATE:主机上存在两个站点(在单独的IP上)是问题所在。如果我删除了另一个站点,上面的设置大部分都会起作用。这样做还带来了另一个问题:chrome不接受网站的安全性,说有些内容没有加密。

我将侦听80的服务器改为重写为https,删除了所有其他指令。

[这实际上应该是一个注释…]

您还应该设置


代理集头X转发协议$方案

要向Django指示连接何时安全,否则您的https链接将被重定向到http,这是错误的

这将在实际为
http
时设置
http
,在为
https
时设置
https

请参阅Django 1.4+上的匹配设置。