Gunicorn 无法在远程 Ubuntu 机器上找到工作目录(Django+nginx+gunicorn)

问题描述 投票:0回答:1

我在 ubuntu 机器上部署了 django 应用程序,但由于

gunicorn.service
中的错误而无法工作(它找不到我编写的工作目录)。 我的工作目录位于
/home/ubunut/project
gunicorn.service

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

[Service]
User=root
Group=www-data
WorkingDirectory=/home/ubuntu/project                                     
ExecStart=/home/ubuntu/project/env/bin/gunicorn --workers 3 --bind unix:/run/gunicorn.sock project.wsgi:application


[Install]
WantedBy=multi-user.target

我进入了

nginx
日志:

2024/07/01 11:04:08 [error] 1906#1906: *23 connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client: myipaddress, server: ipaddress, request: "GET /en/ HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/en/", host: "ipaddress"

所以我输入

 sudo journalctl -u gunicorn.service -f
来实时查看日志:

Jul 01 11:29:17 landingpage (gunicorn)[2472]: gunicorn.service: Changing to the requested working directory failed: No such file or directory
Jul 01 11:29:17 landingpage systemd[1]: gunicorn.service: Main process exited, code=exited, status=200/CHDIR
Jul 01 11:29:17 landingpage systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jul 01 11:29:17 landingpage systemd[1]: gunicorn.service: Start request repeated too quickly.
Jul 01 11:29:17 landingpage systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jul 01 11:29:17 landingpage systemd[1]: Failed to start gunicorn.service - gunicorn daemon.

我尝试使用

pwd
命令转到我的项目根目录并复制路径,检查所有权限。还是不行。我该如何修复gunicorn?

django ubuntu nginx gunicorn
1个回答
0
投票

基于 DigitalOcean 上关于使用 Gunicorn 设置 systemd 的更新文章,您可能需要尝试将

User=root
更改为
User=ubuntu

如果您需要使用

root
用户,那么您应该使用
ls -lhR
检查目录及其子目录和文件的所有者。

© www.soinside.com 2019 - 2024. All rights reserved.