【问题标题】:Nginx permission denied 13 with Django on static content [closed]Nginx 权限在静态内容上被 Django 拒绝 13 [关闭]
【发布时间】:2013-04-07 13:06:09
【问题描述】:

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

权限被拒绝 (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 作为 root 使用 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

【问题讨论】:

  • 您是否使用ls -l检查过您的权限?
  • @thegrinner 是的,因为我被激怒了,我几乎把你能想象到的所有东西都设置为 chown -R www-data:www-data。
  • 检查您的 Nginx 错误日志 - 它们可能会阐明问题。
  • @krak3n 已经这样做了。它说权限被拒绝 13. 错误和访问日志给了我任何用处。并且没有任何已发布的修复可以帮助我。我以 root 用户身份进行设置,安装 virtualenv 等。我应该创建一个新用户吗?
  • 请检查 nginx 是否以用户 www-data 有效运行。此外,您是在实际静态文件还是目录本身上运行测试?另外,请发布您的 nginx 配置。

标签: python django nginx


【解决方案1】:

所以你的 nginx 在/root 内以www-data 的身份运行...这可不好。 /root 不能被普通用户访问(除非你 chmod +x 它,这是个坏主意)。

您应该将您的数据移出它,在/srv/http/var/www/home/whatever 中,但不要在/root 中。

【讨论】:

  • 刚刚意识到这一点。 :)
  • 那我可以把静态文件放在哪里?
  • @Raja 正如我在回答中所说:/srv/http/var/www/home/whatever... 任何你喜欢的东西,真的,只要它是 nginx 用户可读的。
【解决方案2】:

如果你的 nginx 不在生产中,你可以添加“error_log /path/to/log debug;”然后尝试访问您的静态内容之一。你会看到 nginx 试图在调试文件中加载什么。应该很有用。

不要犹豫,把它的内容贴在这里帮助我们理解。

【讨论】:

    猜你喜欢
    • 2017-07-23
    • 2017-11-03
    • 2013-09-13
    • 2016-02-02
    • 2015-05-03
    • 2016-06-15
    • 2021-01-17
    • 2018-02-05
    相关资源
    最近更新 更多