Django Nginx 和 Gunicorn .sock 在连接到上游时失败(2:没有这样的文件或目录)

Kar*_*thu 5 django nginx gunicorn

我是 Python Django 的新手,我已经成功创建了我的应用程序,当我尝试在 Ubuntu 16.04 上托管我的 Django 应用程序时,它无法正常工作,我尝试了几种方法并用 Google 搜索了很多,请帮助摆脱这种情况。

\n\n

我按照这个 URL How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu我已经正确完成了所有设置,但仍然没有成功。在这里我分享必要的文件供您参考,如果我遗漏了什么,请告诉我。

\n\n

etc/nginx/站点可用

\n\n
server {\n    listen *:91;\n    server_name ip-address;\n    location = /favicon.ico { access_log off; log_not_found off; }\n    location /static/ {\n            root /home/iradmin/django/scm;\n    }\n    location / {\n            include proxy_params;\n            proxy_pass http://unix:/home/iradmin/django/scm/scm.sock;\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

等/inint/gunicorn.conf

\n\n
decription "Gunicorn application server handling scm"\nstart on runlevel [2345]\nstop on runlevel [!2345]\nrespawn\nsetuid iradmin\nsetgid www-data\nchdir /home/iradmin/django/scm/\nexec python3venv/bin/gunicorn --workers 3 --bind unix:/home/iradmin/django/scm/scm.sock scm.wsgi:application\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我完成部署的所有步骤时,我在 nginx/error.log 中收到以下错误

\n\n
2018/06/25 18:59:50 [crit] 32640#32640: *8 connect() to unix:/home/iradmin/django/scm/scm.sock failed (2: No such file or directory) while connecting to upstream, client: 10.200.101.124, server: ip-address, request: "GET / HTTP/1.1", upstream: "http://unix:/home/iradmin/django/scm/scm.sock:/", host: "10.200.101.227:91"\n2018/06/25 18:59:52 [crit] 32640#32640: *10 connect() to unix:/home/iradmin/django/scm/scm.sock failed (2: No such file or directory) while connecting to upstream, client: 10.200.101.124, server: ip-address, request: "GET / HTTP/1.1", upstream: "http://unix:/home/iradmin/django/scm/scm.sock:/", host: "10.200.101.227:91"\n[ N 2018-06-25 19:02:33.5097 32620/T4 age/Cor/CoreMain.cpp:1068 ]: Checking whether to disconnect long-running connections for process 32725, application /var/www/pyraMID (production)\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我的应用程序结构\n在此输入图像描述

\n\n

枪兽状态

\n\n
root@iradmin-OptiPlex-3040:/etc/init# sudo service gunicorn status\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 Mon 2018-06-25 19:15:22 IST; 33min ago\n Main PID: 5226 (code=exited, status=216/GROUP)\n\nJun 25 19:15:22 iradmin-OptiPlex-3040 systemd[1]: Started gunicorn daemon.\nJun 25 19:15:22 iradmin-OptiPlex-3040 systemd[1]: gunicorn.service: Main process exited, code=exited, status=216/GROUP\nJun 25 19:15:22 iradmin-OptiPlex-3040 systemd[1]: gunicorn.service: Unit entered failed state.\nJun 25 19:15:22 iradmin-OptiPlex-3040 systemd[1]: gunicorn.service: Failed with result \'exit-code\'.\n
Run Code Online (Sandbox Code Playgroud)\n\n

我尝试了几种方法,但我仍然不知道 .sock 文件以及如何创建它?我真的很感谢您的回复。

\n

小智 0

文件“.sock”将通过正确的配置自动创建。无需手动创建。在etc/inint/gunicorn.confi文件中给出gunicorn的绝对值

exec python3venv/bin/gunicorn
Run Code Online (Sandbox Code Playgroud)

应该

exec /path/.../python3venv/bin/gunicorn
Run Code Online (Sandbox Code Playgroud)