【问题标题】:Gunicorn and Django error permission denied for sock袜子的 Gunicorn 和 Django 错误权限被拒绝
【发布时间】:2017-06-16 13:09:07
【问题描述】:

尝试使用 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'.

【问题讨论】:

    标签: django nginx gunicorn


    【解决方案1】:

    您的 gunicorn 进程以用户 Ubuntu 和组 www-data 身份运行

    [Service]
    User=ubuntu
    Group=www-data
    

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

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

    假设您有 www-data 作为上述文件夹的组。如果没有,你可以改变它

    sudo chgrp www-data /home/ubuntu/
    

    【讨论】:

    • 试过这个文件不存在所以我上传了一个同名的文件到文件夹应用权限到文件夹检查日志(仍然得到502)权限被拒绝2017/01/31 08:10:57 [crit] 31000#31000: *13 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"跨度>
    • 你不能简单地把文件放在那里!!那是 gunicorn 在启动时创建的套接字。如果那里没有文件,则意味着 gunicorn 没有运行。删除您的虚拟文件并再次启动 gunicorn 并查看该文件是否存在。
    • 更新了细节,文件没有创建,还包括gunicorn状态日志。
    • 创建了一个相关问题@e4c5 stackoverflow.com/questions/41955530/…
    • 看起来很棒
    猜你喜欢
    • 1970-01-01
    • 2013-01-25
    • 2023-02-26
    • 2013-01-05
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 1970-01-01
    • 2014-11-10
    相关资源
    最近更新 更多