Gunicorn.service:无法确定用户凭据:没有这样的进程 - django、gunicorn 和 nginx

Rob*_*obo 5 python django nginx gunicorn

当我运行时sudo systemctl status gunicorn,出现以下错误:

\n
\xe2\x97\x8f gunicorn.service - gunicorn daemon\n   Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)\n   Active: failed (Result: exit-code) since Tue 2022-02-08 07:29:18 UTC; 17min ago\n Main PID: 21841 (code=exited, status=217/USER)\n\nFeb 08 07:29:18 ip-172-31-37-113 systemd[1]: Started gunicorn daemon.\nFeb 08 07:29:18 ip-172-31-37-113 systemd[21841]: gunicorn.service: Failed to determine user credentials: No such process\nFeb 08 07:29:18 ip-172-31-37-113 systemd[21841]: gunicorn.service: Failed at step USER spawning /home/ubuntu/bookclub/venv/bin/gun\nFeb 08 07:29:18 ip-172-31-37-113 systemd[1]: gunicorn.service: Main process exited, code=exited, status=217/USER\nFeb 08 07:29:18 ip-172-31-37-113 systemd[1]: gunicorn.service: Failed with result \'exit-code\'.\n
Run Code Online (Sandbox Code Playgroud)\n

我正在按照DigitalOcean 的本教程将我的 Django 网站连接到我的 EC2 实例上。我使用 Nginx 和 Gunicorn 以及 Django 来完成此任务。

\n

这是我的gunicorn.service文件/etc/systemd/system/gunicorn.service

\n
[Unit]\nDescription=gunicorn daemon\nAfter=network.target\n\n[Service]\nUser=sammy\nGroup=www-data\nWorkingDirectory=/home/ubuntu/bookclub\nExecStart=/home/ubuntu/bookclub/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/bookclub/books.sock books.wsgi:application\n\n[Install]\nWantedBy=multi-user.target\n
Run Code Online (Sandbox Code Playgroud)\n

books.sock我在我的项目文件夹中检查了ls,发现它books.sock 不存在

\n

编辑

\n

我将UserGunicorn 服务文件从sammy(不存在)更改为ubuntu(服务器上唯一存在的)。

\n

所以我gunicorn.service现在看起来像这样:

\n
[Unit]\nDescription=gunicorn daemon\nAfter=network.target\n\n[Service]\nUser=sammy\nGroup=www-data\nWorkingDirectory=/home/ubuntu/bookclub\nExecStart=/home/ubuntu/bookclub/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/bookclub/books.sock books.wsgi:application\n\n[Install]\nWantedBy=multi-user.target\n
Run Code Online (Sandbox Code Playgroud)\n

但我收到另一个错误:

\n
\xe2\x97\x8f gunicorn.service - gunicorn daemon\n   Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)\n   Active: failed (Result: exit-code) since Tue 2022-02-08 09:23:41 UTC; 19s ago\n Main PID: 22533 (code=exited, status=203/EXEC)\n\nFeb 08 09:23:41 ip-172-31-37-113 systemd[1]: Started gunicorn daemon.\nFeb 08 09:23:41 ip-172-31-37-113 systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC\nFeb 08 09:23:41 ip-172-31-37-113 systemd[1]: gunicorn.service: Failed with result \'exit-code\'.\n
Run Code Online (Sandbox Code Playgroud)\n

小智 1

您被误导了,因为在会话开始时需要遵循一个外部过程:初始服务器设置指南

去做:

创建用户sammy

重要的

usermod -aG sudo sammy
Run Code Online (Sandbox Code Playgroud)

切换到 Sammy 个人资料

在 sammy 配置文件下创建 django 项目

pwd
/home/sammy
Run Code Online (Sandbox Code Playgroud)

一切都会很好

原因 ?1_可能这是数据库用户 2_可能根配置文件无效。天知道。祝你好运。