【问题标题】:Getting 502 Bad gateway - Nginx & Gunicorn获取 502 Bad gateway - Nginx 和 Gunicorn
【发布时间】:2020-09-01 06:18:49
【问题描述】:

我正在尝试使用 Gunicorn 和 Django 设置 Nginx,但收到 502 bad gateway 错误。以下是我的文件。

gunicorn.service

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

[Service]
User=root
Group=www-data
WorkingDirectory=/root/apio/apio/
ExecStart=/root/sweetapi_env/bin/gunicorn \
         --access-logfile - \
         --workers 3 \
         --bind unix:/run/gunicorn.sock \
        apio.wsgi:application

[Install]
WantedBy=multi-user.target

我的 nginx.conf 文件

server {
        listen 80;
        server_name MY_IP_ADDRESS;
        location / {
                include proxy_params;
                proxy_pass http://unix:/run/gunicorn.sock;
        }

}

我的文件夹结构

apio
    apio
        db.sqlite3
        manage.py
        static
        apio
            settings.py
            wsgi.py
            urls.py
            __init__.py

点击我的 IP 地址后,我在 /var/log/nginx/error.log 中得到以下信息

2020/05/15 12:08:15 [error] 31068#31068: *1 connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while 
connecting to upstream, client: 117.203.***.***, server: ***.**.**.**, 
request: "GET / HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/"

我的 gunicorn.socket 测试也失败了

gunicorn.socket - gunicorn socket
   Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
   Active: failed (Result: service-start-limit-hit) since Fri 2020-05-15 11:58:41 UTC; 12min ago
   Listen: /run/gunicorn.sock (Stream)

请提供一些指示。我该如何调试?

【问题讨论】:

    标签: django nginx gunicorn


    【解决方案1】:

    Guess Gunicorn 没有正确安装在虚拟环境中。我的 Gunicorn.socket 日志给了我线索。

    sudo journalctl -u gunicorn
    May 15 11:19:34 ubuntu-s-1vcpu-1gb-blr1-01 systemd[29716]: gunicorn.service: Failed to execute command: No such file or directory
    May 15 11:19:34 ubuntu-s-1vcpu-1gb-blr1-01 systemd[29716]: gunicorn.service: Failed at step EXEC spawning /root/sweetapi_env/bin/gunicorn: No such file or directory
    

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 2018-08-03
      • 2016-04-20
      • 2020-11-28
      • 2016-01-04
      • 2014-04-30
      • 2020-06-12
      • 2016-03-26
      • 2019-01-22
      相关资源
      最近更新 更多