使用 gunicorn 部署 Django 应用程序时出错

时间:2021-02-05 10:04:33

标签: django linux web-deployment gunicorn

我正在尝试按照本教程在 Linux 服务器中部署我的 Django 应用程序 https://www.digitalocean.com/community/tutorials/como-configurar-django-con-postgres-nginx-y-gunicorn-en-ubuntu-18-04-es

但是在尝试使用我的 django 项目设置 gunicorn 时不断收到错误

● gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2021-02-04 17:45:34 +01; 25min ago
TriggeredBy: ● gunicorn.socket
   Main PID: 754981 (code=exited, status=217/USER)

Feb 04 17:45:34 vps141106 systemd[1]: Started gunicorn daemon.
Feb 04 17:45:34 vps141106 systemd[754981]: gunicorn.service: Failed to determine user credentials: No such process
Feb 04 17:45:34 vps141106 systemd[754981]: gunicorn.service: Failed at step USER spawning /home/root/venv/bin/gunicorn: No such process
Feb 04 17:45:34 vps141106 systemd[1]: gunicorn.service: Main process exited, code=exited, status=217/USER
Feb 04 17:45:34 vps141106 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Feb 04 17:45:34 vps141106 systemd[1]: gunicorn.service: Start request repeated too quickly.
Feb 04 17:45:34 vps141106 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Feb 04 17:45:34 vps141106 systemd[1]: Failed to start gunicorn daemon.

这是我的服务

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

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

[Install]
WantedBy=multi-user.target

我收到这些错误

gunicorn.service: Failed to determine user credentials: No such process
gunicorn.service: Failed at step USER spawning /home/root/venv/bin/gunicorn: No such process

现在我很确定我在 /home/root/venv/bin/gunicorn 中有一些东西我刚刚做了一个

nano /home/root/venv/bin/gunicorn 得到这个

  GNU nano 4.8                                           /home/root/venv/bin/gunicorn                                                     
#!/home/root/venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from gunicorn.app.wsgiapp import run
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(run())

当然,以防万一我在我的 venv 中执行了“pip install gunicorn”并且它实际上已安装

现在出现第一个错误,我不确定是什么原因造成的,系统用户被称为 root 并且具有 sudo 权限,也许我需要将密码放在某处以确保它可以登录?

希望大家帮帮我。

0 个答案:

没有答案