我已经使用Nginx和uwsgi在CentOS 6.5上设置了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",主机:&#34 ; myapi.dev",推荐人:" http://myapi.dev/api/v1/datasets/"
# 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
有人能指出我正确的方向吗?
答案 0 :(得分:1)
需要时间,但我自己已经解决了这个问题。将用户从 amar更改为root ,并将静态文件夹权限设置为 666 。希望将来有人帮助。
答案 1 :(得分:0)
可能与SELinux有关。您需要允许HTTPD脚本和模块连接到网络。
setsebool httpd_can_network_connect on -P