Django 使用自签名证书为SSL重新配置Nginx时出现问题
我在Digital Ocean上有一个VPS,带有Ubuntu18.04、Nginx、Gunicorn、Django和一个测试web应用程序,所有这些都配置为(ufw)使用http:80。一切都很完美 现在我修改了文件/sites available/LibrosWeb,允许使用自签名证书进行SSL通信,因为我没有域。结果“错误502坏网关” 这是适用于http:80的初始代码:Django 使用自签名证书为SSL重新配置Nginx时出现问题,django,ssl,nginx,Django,Ssl,Nginx,我在Digital Ocean上有一个VPS,带有Ubuntu18.04、Nginx、Gunicorn、Django和一个测试web应用程序,所有这些都配置为(ufw)使用http:80。一切都很完美 现在我修改了文件/sites available/LibrosWeb,允许使用自签名证书进行SSL通信,因为我没有域。结果“错误502坏网关” 这是适用于http:80的初始代码: server{ #Configuracion http listen 80; listen
server{
#Configuracion http
listen 80;
listen [::]:80;
server_name 15.15.15.15;
location = /favicon.ico { access_log off; log_not_found off; }
location /robots.txt {
alias /var/www/LibrosWeb/robots.txt ;
}
location /static/ {
root /home/gela/LibrosWeb;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
这是允许SSL的代码(错误502):
UFW配置为:
80,443/tcp (Nginx Full) ALLOW IN Anywhere
80,443/tcp (Nginx Full (v6)) ALLOW IN Anywhere (v6)
文件/etc/nginx/snippets/self-signed.conf和/etc/nginx/snippets/ssl-params.conf与本教程中的文件相同
我已经测试了两天的配置,我最多只能做一半,也就是说,我可以显示django的默认页面,但不能显示我的应用程序的默认页面,如果我这样放置代码:
server{
#Configuracion http
listen 80;
listen [::]:80;
server_name 15.15.15.15;
return 302 https://15.15.15.15$request_uri;
location = /favicon.ico { access_log off; log_not_found off; }
location /robots.txt {
alias /var/www/LibrosWeb/robots.txt ;
}
location /static/ {
root /home/gela/LibrosWeb;
}
}
server{
#Configuracion SSL
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name 15.15.15.15;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
location / {
include proxy_params;
proxy_pass https://unix:/run/gunicorn.sock;
}
}
什么是错的,什么是缺失的?我想我痛苦的日子已经过去了。在阅读了数百条日志之后,我发现了这个问题。将Whitenoise更新为4.0,您必须在其中更改配置的形状,这导致使用我的旧配置时gunicorn服务将抛出错误。其余的都好 谢谢你的帮助。
您好。为什么要从ssl服务器返回重定向??如果客户端使用http输入,它将被重定向到https。能否在
代理\u pass中将https
更改为http
https://unix:/run/gunicorn.sock;代码>?Selcuk,我也尝试过,但不起作用,它给出了相同的错误502。我看起来像一个疯狂的网络人,我找不到解决办法。
server{
#Configuracion http
listen 80;
listen [::]:80;
server_name 15.15.15.15;
return 302 https://15.15.15.15$request_uri;
location = /favicon.ico { access_log off; log_not_found off; }
location /robots.txt {
alias /var/www/LibrosWeb/robots.txt ;
}
location /static/ {
root /home/gela/LibrosWeb;
}
}
server{
#Configuracion SSL
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name 15.15.15.15;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
location / {
include proxy_params;
proxy_pass https://unix:/run/gunicorn.sock;
}
}