【发布时间】:2018-09-04 00:26:09
【问题描述】:
我在 Digital Ocean 上有一个带有 Ubuntu 18.04、Nginx、Gunicorn、Django 和一个测试 Web 应用程序的 VPS,所有配置 (ufw) 都可以使用 http:80。一切正常。 Tutorial
现在我修改文件 /sites-available/LibrosWeb 以允许使用自签名证书的 SSL 流量,因为我没有域。 Tutorial。结果“错误 502 Bad Gateway”。
这是与 http:80 配合良好的初始代码:
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):
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 = /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 https://unix:/run/gunicorn.sock;
}
}
server{
#Configuracion http
listen 80;
listen [::]:80;
server_name 15.15.15.15;
return 302 https://15.15.15.15$request_uri;
}
UFW 配置为:
80,443/tcp (Nginx Full) ALLOW IN Anywhere
80,443/tcp (Nginx Full (v6)) ALLOW IN Anywhere (v6)
文件 /etc/nginx/sn-ps/self-signed.conf 和 /etc/nginx/sn-ps/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;
}
}
出了什么问题,或者缺少什么?
【问题讨论】:
-
你为什么要从 ssl 服务器返回重定向? linode.com/docs/web-servers/nginx/…
-
如果客户端使用http进入,则重定向到https。
-
你能把
proxy_pass https://unix:/run/gunicorn.sock;中的https改成http吗? -
Selcuk,我也试过了,但它不起作用,它给出了同样的错误 502。我看起来像一个疯狂的网络人,我找不到解决方案。