Gunicorn和Django对袜子的错误许可被拒绝

时间:2017-01-31 07:20:39

标签: django nginx gunicorn

尝试使用django和gunicorn在nginx日志文件中设置此错误:

2017/01/31 07:04:50 [crit] 30386#30386: *1 connect() to unix:/home/ubuntu/webapps/kenyabuzz/kb.sock failed (13: Permission denied) 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"

正确提供静态文件。 nginx / sites-enabled设置中的gunicorn文件

#kb gunicorn nginx settings

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

    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # 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设置/etc/systemd/system/gunicorn.service

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

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

[Install]
WantedBy=multi-user.target

检查了gunicorn的状态

ubuntu@ip-172-31-16-133:/etc/nginx/sites-enabled$ sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
   Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2017-01-31 06:59:49 UTC; 8min ago
 Main PID: 30281 (code=exited, status=203/EXEC)

Jan 31 06:59:48 ip-172-31-16-133 systemd[1]: Started gunicorn daemon.
Jan 31 06:59:49 ip-172-31-16-133 systemd[1]: gunicorn.service: Main process exited, code=exited, sta
Jan 31 06:59:49 ip-172-31-16-133 systemd[1]: gunicorn.service: Unit entered failed state.
Jan 31 06:59:49 ip-172-31-16-133 systemd[1]: gunicorn.service: Failed with result 'exit-code'.

1 个答案:

答案 0 :(得分:4)

您的gunicorn进程以用户Ubuntu和Group www-data

运行
chmod g+x /home/ubuntu/
chmod g+r /home/ubuntu/

通常在ubuntu中,nginx作为www-data运行。我看到你已经将www-data定义为gunicorn的组。因此,您可以通过

解决此问题
sudo chgrp www-data /home/ubuntu/

假设您有www-data作为上述文件夹的组。如果没有,您可以使用

进行更改
- name: Clean all packages
  command: yum clean all && yum makecache