python - Nginx 权限被 Django 拒绝 13 静态内容

标签 python django nginx

<分区>

我用了这个tutorial设置 virtualenv 和 nginx 服务器。 我完全按照吩咐做了,但我仍然得到一个

Permission denied (13)

尝试访问静态内容时出错。 我已经将我的静态目录和整个 Django 项目设置为归 www-data 所有。

此外,如果我忽略静态内容并尝试让所有内容都与 emperor 一起运行,我会遇到更多权限被拒绝的错误。现在每次我尝试访问该网站时。

root      8704  0.0  0.0  62780  1260 ?        Ss   16:19   0:00 nginx: master process /usr/sbin/nginx
www-data  8705  0.0  0.0  63108  1680 ?        S    16:19   0:00 nginx: worker process
www-data  8706  0.0  0.0  63108  1680 ?        S    16:19   0:00 nginx: worker process
www-data  8707  0.0  0.0  63108  1680 ?        S    16:19   0:00 nginx: worker process
www-data  8708  0.0  0.0  63448  2276 ?        S    16:19   0:00 nginx: worker process

启动uwsgi时:https://gist.github.com/anonymous/f19997fd07c0237a7435作为根 使用 www-data 启动 uwsgi 时:

root@vmd2719:~/energy1/energydrinks# uwsgi --ini django.ini --uid www-data --gid www-data
[uWSGI] getting INI configuration from django.ini
open("./python27_plugin.so"): No such file or directory [core/utils.c line 3321]
!!! UNABLE to load uWSGI plugin: ./python27_plugin.so: cannot open shared object file: No such file or directory !!!
*** Starting uWSGI 1.9.6 (64bit) on [Mon Apr 15 16:24:49 2013] ***
compiled with version: 4.6.3 on 15 April 2013 11:52:36
os: Linux-3.2.0-40-generic #64-Ubuntu SMP Mon Mar 25 21:22:10 UTC 2013
nodename: vmd2719
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /root/energy1/energydrinks
writing pidfile to /tmp/energy-master.pid
detected binary path: /usr/local/bin/uwsgi
setgid() to 33
setuid() to 33
chdir(): Permission denied [core/uwsgi.c line 2063]
chdir(): Permission denied [core/uwsgi.c line 1249]
chdir(): Permission denied [core/uwsgi.c line 1269]

访问静态文件的Nginx调试日志:

2013/04/15 16:20:25 [debug] 8708#0: *1 http filename: "/root/energy1/energydrinks/static/jgrowl/jquery.jgrowl.js"
2013/04/15 16:20:25 [debug] 8708#0: *1 add cleanup: 0000000001F68C10
2013/04/15 16:20:25 [error] 8708#0: *1 open() "/root/energy1/energydrinks/static/jgrowl/jquery.jgrowl.js" failed (13: Permission denied), client: 109.193.75.142, server: .de, request: "GET /static/jgrowl/jquery.jgrowl.js HTTP/1.1", host: ".de:8000", referrer: "http://.de:8000/member/register/"
2013/04/15 16:20:25 [debug] 8708#0: *1 http finalize request: 403, "/static/jgrowl/jquery.jgrowl.js?" a:1, c:1
2013/04/15 16:20:25 [debug] 8708#0: *1 http special response: 403, "/static/jgrowl/jquery.jgrowl.js?"
2013/04/15 16:20:25 [debug] 8708#0: *1 http set discard body
2013/04/15 16:20:25 [debug] 8708#0: *1 xslt filter header
2013/04/15 16:20:25 [debug] 8708#0: *1 charset: "" > "utf-8"
2013/04/15 16:20:25 [debug] 8708#0: *1 HTTP/1.1 403 Forbidden

最佳答案

因此,您的 nginx 在 /root 中作为 www-data 运行……这不太好。 /root 普通用户无法访问(除非你 chmod +x 它,这是个坏主意)。

你应该把你的数据移到它之外,在 /srv/http, /var/www/home/whatever 中,但是不在 /root 中。

关于python - Nginx 权限被 Django 拒绝 13 静态内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16014816/

相关文章:

python - django.core.exceptions.ImproperlyConfigured : 'django_mongodb_engine' isn't an available database backend

nginx - 无法在nginx+php-fpm上运行.html文件

python - 根据关键词 Pandas DF 提取列名

python - 如果字典中的键重复,如何引发错误

python - Django Group By 返回不同的值

django - Django Rest Framework View 集中的对象级授权

nginx - 如何在维护模式下使用 Nginx 提供静态 Assets (503)

linux - nginx 作为缓存代理不缓存任何东西

python - 只检查循环语句一次

python - 使用 matplotlib 动画波脉冲