权限被拒绝访问静态文件 Nginx +uwsgi +Django

Permission denied Accessing static files Nginx +uwsgi +Django

我已经在 CentOS 6.5 上用 Nginx 和 uwsgi 安装了 Django 项目。

访问静态内容时出现如下错误 (/var/log/nginx/error.log)- 2015/11/02 19:05:37 [错误] 29701#0: *52 open() "/home/amar/workspace/myproj/config/static/rest_framework/js/default.js" 失败(13:权限被拒绝),客户端:172.29.100.104,服务器:myapi.dev,请求:"GET /static/rest_framework/js/default.js HTTP/1.1",主机:"myapi.dev",推荐人:“http://myapi.dev/api/v1/datasets/

我的/etc/nginx/conf.d/virtual.conf如下图-

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///tmp/uwsgi.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
#
#API
#
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name myapi.dev; # substitute your machine's IP address or FQDN
    charset     utf-8;

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

    location /static {
    autoindex  on;
        alias /home/amar/workspace/myproj/config/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
    }
}

这是我的 uwsgi.ini 文件:


[uwsgi]

chdir = /home/amar/workspace/myproj
#home = %(base)/.virtualenvs/myproj
module = config.wsgi:application

home = /home/amar/.virtualenvs/myproj

master = true
processes = 3

socket = /tmp/uwsgi.sock
chmod-socket = 777
vacuum = true

有人能给我指出正确的方向吗?

可能与 SELinux 有关。您将需要允许 HTTPD 脚本和模块连接到网络。

setsebool httpd_can_network_connect on -P

这需要时间,但我已经自己解决了这个问题。将用户从 amar 更改为 root,并将静态文件夹权限设置为 666。希望对以后的人有帮助。