gpt4 book ai didi

python - Nginx 在静态文件上抛出 403 Forbidden

转载 作者:IT老高 更新时间:2023-10-28 21:05:49 25 4
gpt4 key购买 nike

我有一个 django 应用程序,python 2.7,带有 gunicorn 和 nginx。

如果我尝试查看我的 static 文件夹 @:

中的任何内容,Nginx 会抛出 403 Forbidden Error
/home/ubuntu/virtualenv/myapp/myapp/homelaunch/static

nginx 配置(/etc/nginx/sites-enabled/myapp) 包含:

server {
listen 80;
server_name *.myapp.com;
access_log /home/ubuntu/virtualenv/myapp/error/access.log;
error_log /home/ubuntu/virtualenv/myapp/error/error.log warn;
connection_pool_size 2048;

fastcgi_buffer_size 4K;
fastcgi_buffers 64 4k;

root /home/ubuntu/virtualenv/myapp/myapp/homelaunch/;

location /static/ {
alias /home/ubuntu/virtualenv/myapp/myapp/homelaunch/static/;
}

location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}

error.log 包含:

2013/11/24 23:00:16 [error] 18243#0: *277 open() "/home/ubuntu/virtualenv/myapp/myapp/homelaunch/static/img/templated/home/img.png" failed (13: Permission denied), client: xx.xx.xxx.xxx, server: *.myapp.com, request: "GET /static/img/templated/home/img2.png HTTP/1.1", host: "myapp.com", referrer: "http://myapp.com/"

access.log 包含

xx.xx.xx.xxx - - [24/Nov/2013:23:02:02 +0000] "GET /static/img/templated/base/animg.png HTTP/1.1" 403 141 "http://myapp.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:25.0) Gecko/20100101 Firefox/25.0"
xx.xx.xx.xxx - - [24/Nov/2013:23:02:07 +0000] "-" 400 0 "-" "-"

我试着在 /static/ 中查看一个 .css 文件,它在源代码中抛出了这样的错误:

<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.1.19</center>
</body>
</html>

最佳答案

MacOs El Capitan:在nginx.conf的顶部写user username group_name

我的用户名是卡米尔,所以我写:

user Kamil staff;

(“员工”这个词在 macOS 中非常重要)。这可以解决问题。之后,您无需更改项目文件夹和文件中的任何权限。

关于python - Nginx 在静态文件上抛出 403 Forbidden,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20182329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com