【问题标题】:.sock file not appearing in project directory with gunicorn.sock 文件没有出现在带有 gunicorn 的项目目录中
【发布时间】:2018-10-02 06:08:15
【问题描述】:

我正在尝试为我的网络服务器设置 gunicorn,我目前正在学习本教程:https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04#create-a-gunicorn-systemd-service-file

问题是gunicorn没有在我的项目目录下生成myproject.sock文件。

我在这个文件中的配置:/etc/systemd/system/gunicorn.service,看起来像这样:

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

[Service]
User=daniel
Group=www-data
WorkingDirectory=/home/daniel/myproject
ExecStart=/home/daniel/myproject/myproject_venv/bin/python3 home/daniel/myproject/myproject_venv/bin/gunicorn --workers 3 -b :8000     myproject.wsgi:application

[Install]
WantedBy=multi-user.target

我正在使用来自 Digital Ocean 的 Django 作为我的 Web 服务器,所以一开始,服务器就带有文件和目录,例如 django/django_project/django_project。 但是我没有使用已经制作的文件,而是使用新目录创建了一个新项目(正如教程所说)。

查看 gunicorn 错误日志时,顶部带有 sudo journalctl -u gunicorn,它说:

Listening at: unix:/home/django/gunicorn.socket (1915)

如上所述,我创建了一个新项目,其目录与 django 的目录不同,因此我正在寻找一种方法来更改 gunicorn 正在听的位置。具体来说,我希望它在home/daniel/myproject/myproject.sock 收听。

很遗憾,myproject.sock 由于某种原因不存在。

我的项目文件归 sudo 用户和组所有,因此 unicorn 可以访问。 工作目录应该是正确的。

感谢任何帮助,因为我对 nginx、unicorn 和 django 非常陌生。

【问题讨论】:

    标签: django nginx gunicorn digital-ocean


    【解决方案1】:

    试试--bind unix:/home/daniel/myproject/myproject.sock,而不是-b :8000。我自己没有使用 gunicorn,但我猜它现在绑定到 tcp 端口 8000。

    【讨论】:

    • 这个答案和对/etc/systemd/system/gunicorn.service 模板的一些审查为我解决了这个问题。非常感谢!
    猜你喜欢
    • 2018-12-04
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 2020-07-10
    • 1970-01-01
    • 1970-01-01
    • 2022-08-02
    • 2020-07-18
    相关资源
    最近更新 更多