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

falq053o  于 2022-11-02  发布在  Nginx
关注(0)|答案(2)|浏览(199)

我已经在CentOS 6.5上用Nginx和uwsgi安装了Django项目。
我在访问静态内容时遇到如下错误(/var/log/nginx/error.log)- 2015/11/02 19:05:37 [错误] 29701#0:*52打开“/home/amar/workspace/myproj/config/static/rest_framework/js/default.js”失败(13:权限被拒绝),客户端:172.29.100.104服务myapi.dev请求:“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

谁能给我指个方向?

dhxwm5r4

dhxwm5r41#

虽然花了点时间,但我已经自己解决了这个问题。将用户从amar更改为root,并将静态文件夹权限设置为666。希望它能对将来的用户有所帮助。

vhmi4jdf

vhmi4jdf2#

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

setsebool httpd_can_network_connect on -P

相关问题