我正在开发一个特定的 Django 项目(不知道这是否有什么不同,但服务提供商是 Hostinger)。相同的部署是在带有 ubuntu 的 vps 服务器上完成的。我已经计划使用gunicorn和nginx,但我不断遇到
502 网关错误错误 闲逛时发现gunicorn没有启动
以下是我运行时收到的错误
sudo systemctl status gunicorn
错误:
× gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2024-01-02 07:53:47 UTC; 4 days ago
TriggeredBy: ● gunicorn.socket
Main PID: 6153 (code=exited, status=203/EXEC)
CPU: 1ms
Jan 02 07:53:47 srv457341 systemd[1]: Started gunicorn daemon.
Jan 02 07:53:47 srv457341 systemd[6153]: gunicorn.service: Failed to execute /root/Assistanza/Assistanza/env/bin/gunicorn: No such file or directory
Jan 02 07:53:47 srv457341 systemd[6153]: gunicorn.service: Failed at step EXEC spawning /root/Assistanza/Assistanza/env/bin/gunicorn: No such file or directory
Jan 02 07:53:47 srv457341 systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Jan 02 07:53:47 srv457341 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jan 02 07:53:47 srv457341 systemd[1]: gunicorn.service: Start request repeated too quickly.
Jan 02 07:53:47 srv457341 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jan 02 07:53:47 srv457341 systemd[1]: Failed to start gunicorn daemon.
实现这一点的路径是: /root/Assistanza/Assistanza
以下是gunicorn的服务文件:
[Unit]
Description=gunicorn daemon Requires=gunicorn.socket After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/root/Assistanza/Assistanza
ExecStart=/root/Assistanza/Assistanza/env/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
Assistanza.wsgi:application
[Install]
WantedBy=multi-user.target
~ ~
我该如何解决这个问题?
此错误消息表明您的环境中未安装
gunicorn
模块。
激活您的环境并执行以下命令:
pip install gunicorn
你需要安装gunicorn。
如果你已经安装了
gunicorn
你可以使用[whilebeing in env]:
which gunicorn
如果它显示了您的环境路径,那么您的环境是正确的,否则环境可能已损坏。考虑使用以下方法创建新的虚拟环境:
deactivate
virtualenv env
并安装要求... 如果错误仍然存在,请考虑检查文件路径和权限。
我建议仔细阅读这份文件: DIGITALOCEAN-UBUNTU1604.
在您的文件夹中存在 .sock 文件之前,您的
gunicorn
无法正常运行。
希望这对您有帮助!