套接字文件上的 Django 权限被拒绝

套接字文件上的 Django 权限被拒绝

我正在尝试在 Centos 7 服务器上设置 Django 通过 NGINX 运行,但是我似乎遇到了一连串的问题。我现在遇到的主要问题是 NGINX 在套接字文件上给我一个权限被拒绝的错误。我浏览了所有我能找到的关于这个问题的 SO 帖子和博客文章,但都不起作用。有人能帮我指出我做错了什么吗:

目前这是我的 /etc/nginx/nginx.conf 文件:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
    listen 80;
        server_name IPADDRESS;

        location = favicon.ico { access_log off; log_not_found off; }
        location /static/ {
            root /home/user_name/project_name;
        }

    location / {
            include uwsgi_params;
            uwsgi_pass unix:/var/uwsgi/project_name.sock;
        }
    }
}

这是我的 uwsgi 配置文件:

[uwsgi]
project = project_name
username = user_name
base = /home/%(username)

chdir = %(base)/%(project)
module = %(project).wsgi:application

master = true
processes = 5

uid = %(username)
socket = /var/uwsgi/%(project).sock
chown-socket = %(username):nginx
chmod-socket = 666
vacuum = true

这是我的 uwsgi.service 文件:

[Unit]
Description=uWSGI Emperor service

[Service]
ExecStartPre=/usr/bin/bash -c 'mkdir -p /var/uwsgi; chown user_name:nginx /var/uwsgi'
ExecStart=/usr/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

我的访问日志总是打印类似以下内容(根据套接字文件位置以及“unix”后是否有 1 或 3 个 / 进行细微调整):

2016/06/14 15:54:48 [crit] 3073#0: *1 connect() to unix:///var/uwsgi/project_name.sock failed (13: Permission denied) while connecting to upstream, client: FROMIPADDRESS, server: IPADDRESS, request: "GET /events/ HTTP/1.1", upstream: "uwsgi://unix:///var/uwsgi/project_name.sock:", host: "IPADDRESS"

相关内容