【问题标题】:Run Gunicorn service on DigitalOcean starting a Django project在 DigitalOcean 上运行 Gunicorn 服务,开始一个 Django 项目
【发布时间】:2020-10-06 15:33:16
【问题描述】:

我在/etc/systemd/system/gunicorn.service 有以下systemd 文件

[Unit]
Description=Gunicorn daemon for Django Project
Before=nginx.service
After=network.target

[Service]
WorkingDirectory=/home/serverapp
ExecStart=gunicorn --name=avesoft  --bind unix:/home/serverapp/gunicorn.socket --config /etc/gunicorn.d/gunicorn.py WebApp.wsgi:application
Restart=always
SyslogIdentifier=gunicorn
User=root
Group=www-data


[Install]
WantedBy=multi-user.target

当我手动将目录更改为 /home/serverapp 并运行 gunicorn --name=avesoft --bind unix:/home/serverapp/gunicorn.socket --config /etc/gunicorn.d/gunicorn.py WebApp.wsgi:application 时,一切正常,Nginx 通过 Gunicorn 连接到我的 Django 应用程序。

但是通过重新启动服务器,我收到 Bad Gateway 错误,似乎 Gunicorn 尚未开始工作。我不明白我的服务文件不起作用的原因是什么。

【问题讨论】:

  • 当你sudo systemctl start gunicorn时它是否有效?
  • @Mohd 不,它会引发此错误:Reason: Exec format error)

标签: django linux nginx server digital-ocean


【解决方案1】:

所以我通过提供gunicorn 的路径来解决这个问题:

[Unit]
Description=Gunicorn daemon for Django Project
Before=nginx.service
After=network.target

[Service]
WorkingDirectory=/home/serverapp
ExecStart=/usr/bin/gunicorn --name=avesoft  --bind unix:/home/serverapp/gunicorn.socket --config /etc/gunicorn.d/gunicorn.py WebApp.wsgi:application
Restart=always
SyslogIdentifier=gunicorn
User=root
Group=www-data


[Install]
WantedBy=multi-user.target

【讨论】:

    猜你喜欢
    • 2019-03-31
    • 1970-01-01
    • 2014-11-23
    • 2018-03-18
    • 2015-12-05
    • 2019-06-19
    • 1970-01-01
    • 2020-04-06
    • 2015-05-07
    相关资源
    最近更新 更多