Nginx Gunicorn 套接字问题?反应迟钝

Nginx Gunicorn socket issue? Unresponsive

我正在尝试将 Django 项目部署到 AWS Lightsail 服务器。

我主要关注 this tutorial。我添加了一些 SSL 协议以提高安全性。

这个项目在我的 Ubuntu 18.04 VirtualBox 上完美运行,具有完全相同的设置和完全相同的组件,相同的 SSL 协议。但是在 Lightsail 上它不响应浏览器请求。它会将我重定向到 https,但随后会死掉……我无法在任何日志中识别出任何错误。这让我猜测

/etc/systemd/system/webrock.套接字:

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/webrock.sock

[Install]
WantedBy=sockets.target

/etc/systemd/system/webrock.服务:

[Unit]
Description=gunicorn daemon
Requires=webrock.socket
After=network.target

[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/django/webrock
ExecStart=/home/ubuntu/django/webrock/venv/bin/gunicorn \
      --access-logfile - \
      --workers 3 \
      --bind unix:/run/webrock.sock \
      core.wsgi:application

[Install]
WantedBy=multi-user.target

/etc/nginx/sites-available/webrock:

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2 ipv6only=on;

        include snippets/signed.conf; # path to certs
        include snippets/params.conf; # cert related params


        index index.html index.htm index.nginx-debian.html;

        server_name mydomain.com www.mydomain.com; #changed this line by replacing domain name with dummy


        location = /favicon.ico {access_log off; log_not_found off;}
        location /static/ {
                root /home/ubuntu/django/webrock;
        }
        location / {
                include proxy_params;
                proxy_pass http://unix:/run/webrock.sock;
                try_files $uri $uri/ =404;
        }

}
server {
        listen 80;
        listen [::]:80;

        server_name mydomain.com www.mydomain.com; #changed this line by replacing domain name with dummy

        return 302 https://$server_name$request_uri;

}

我留下了nginx默认文件。现在每次打服务器IP访问页面,看到的都是nginx默认页面。当我使用域名时,我被重定向到 HTTPS,但是……什么都没有。我假设 gunicorn 和 nginx 之间存在一些中断,但我没有足够的经验来解决那里的问题或解决它。

正如我上面提到的,完全相同的设置在我的 VirtualBox 中的类似系统上运行完美。

非常感谢您的建议和提示。

更新: 我禁用了 nginx 中的重定向部分并让它监听端口 80。它起作用了。现在我想弄清楚如何将 HTTP2 和端口 443 引入回设置中。顺便说一句,我的 ufw 看起来像这样:

经过两天的努力解决这个问题,这里是解决方案。

所以 Amazon Lightsail 在实际服务器上的 UFW 前面有一个额外的防火墙。 您可以通过单击访问 Lightsail 防火墙...

您实例的菜单 > 管理 > 网络

您将看到您的实例的网络摘要,例如 IP 地址、防火墙、负载均衡器。在该防火墙中,您需要添加一个额外的端口(在我的例子中是 HTTPS)。

他们为什么要在 UFW 前面放置一个额外的防火墙打败了我。