【问题标题】:Trouble with hosting a django app on digital ocean在数字海洋上托管 django 应用程序的问题
【发布时间】:2021-08-27 17:06:29
【问题描述】:

当我访问 http://[ip address] 时,收到 502 bad request 错误。

/etc/systemd/system/gunicorn.socket 文件:

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

/etc/systemd/system/gunicorn.service 文件:

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

[Service]
User=mainuser
Group=www-data
WorkingDirectory=/home/mainuser/Personal_Web
ExecStart=/home/mainuser/Personal_Web/vr/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          myapp.wsgi:application

[Install]
WantedBy=multi-user.target

/etc/nginx/sites-available/myapp 文件:

server {
    listen 80;
    server_name [ip address];

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/mainuser/Personal_Web;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

当我运行 sudo tail -F /var/log/nginx/error.log 时,我收到 connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream 错误。我不知道为什么我会得到这个或如何解决它?

【问题讨论】:

  • 请显示“sudo systemctl status gunicorn.socket”和“sudo journalctl -u 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 Thu 2021-06-10 14:59:38 UTC; 2h 47min ago Triggers: ● gunicorn.service Listen: /run/gunicorn.sock (Stream) 第二个命令显示:Listening on gunicorn socket. Failed with result 'service-start-limit-hit'.@EneP

标签: django nginx gunicorn digital-ocean


【解决方案1】:

我认为你配置错了这一行。

ExecStart=/home/mainuser/Personal_Web/vr/bin/gunicorn \
      --access-logfile - \
      --workers 3 \
      --bind unix:/run/gunicorn.sock \
      myapp.wsgi:application

您确定 myapp.wsgi:application 中的 myapp 是您的 Django 项目中的主文件夹吗?您的主文件夹是包含 settings.py 和 wsgi.py 的文件夹。

您可以尝试将其更改为name_main_folder.wsgi:application吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    • 2022-01-04
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    相关资源
    最近更新 更多