Gunicorn& django:connect()到unix:/home/ubuntu/webapps/kenyabuzz/kb.sock连接上游时失败(2:没有这样的文件或目录)

时间:2017-02-01 12:01:35

标签: django nginx gunicorn

使用gunicorn& amp;设置django站点nginx我可以用gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application运行它但是nginx的gunicorn实例失败并且错误无法连接到sock文件(并且也不会创建它)。

错误日志是:

2017/02/01 11:43:47 [crit] 30225#30225: *9 connect() to unix:/home/ubuntu/webapps/kenyabuzz/kb.sock failed (2: No such file or directory) while connecting to upstream, client: 197.232.12.165, server: kenyabuzz.nation.news, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/webapps/kenyabuzz/kb.sock:/", host: "kenyabuzz.nation.news"

相关设置为/etc/init/gunicorn.conf

description "Gunicorn application server handling all projects"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid user
setgid www-data
chdir /home/ubuntu/webapps/kenyabuzz

exec /home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application

/etc/systemd/system/gunicorn.service

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

[Service]
User=ubuntu
Group=nginx
WorkingDirectory=/home/ubuntu/webapps/kenyabuzz
ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application

[Install]
WantedBy=multi-user.target

nginx conf文件

server {
    listen 80;
    server_name kenyabuzz.nation.news;

    # Django media
    location /media  {
        alias /home/ubuntu/webapps/kenyabuzz/kb/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/ubuntu/webapps/kenyabuzz/kb/static; # your Django project's static files - amend as required
    }

    location /favicon.ico {
        alias /home/ubuntu/webapps/kenyabuzz/kb/static/kb/favicon.ico; # favicon
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/webapps/kenyabuzz/kb.sock;
    }
}

更新

Gunicorn状态

ubuntu@ip-172-31-17-122:~$ 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 Wed 2017-02-01 11:26:01 UTC; 21h ago
  Process: 30211 ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home
 Main PID: 30211 (code=exited, status=216/GROUP)

Feb 01 11:26:01 ip-172-31-17-122 systemd[1]: Started gunicorn daemon.
Feb 01 11:26:01 ip-172-31-17-122 systemd[1]: gunicorn.service: Main process exited, code=exited, sta
Feb 01 11:26:01 ip-172-31-17-122 systemd[1]: gunicorn.service: Unit entered failed state.
Feb 01 11:26:01 ip-172-31-17-122 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
lines 1-10/10 (END)

2 个答案:

答案 0 :(得分:1)

问题在于group将其设置为www-data并且有效。

答案 1 :(得分:0)

配置对我来说很好。确保gunicorn服务实际上正在运行并且具有写入套接字文件的权限。

更新:仔细查看服务状态,服务正在运行。

尝试在shell中运行该命令,看看是否有任何结论性输出。