【问题标题】:Problem when reconfiguring Nginx for SSL with self-signed certificate使用自签名证书为 SSL 重新配置 Nginx 时出现问题
【发布时间】: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。我看起来像一个疯狂的网络人,我找不到解决方案。

标签: django ssl nginx


【解决方案1】:

我想我受苦的日子已经结束了。在阅读了数百条日志后,我发现了问题所在。将 Whitenoise 更新到 4.0,您必须更改配置的形状,导致使用我的旧配置,gunicorn 服务会抛出错误。其他都还好。

http://whitenoise.evans.io/en/stable/django.html#django-middleware

感谢您的帮助。 美好的一天。

【讨论】:

    猜你喜欢
    • 2011-04-26
    • 1970-01-01
    • 2017-09-12
    • 2013-10-05
    • 2021-02-14
    • 1970-01-01
    • 2020-09-20
    • 2011-07-16
    • 2021-12-13
    相关资源
    最近更新 更多