NGINX/Django: 提供静态文件时出现 403 错误
NGINX/Django: 403 error when serving static files
我已经花了很多很多时间调试它,但还没有完全找到解决方案。我已经尝试应用来自十几个相关线程的解决方案,但 none 解决了问题(或者我实施了错误的解决方案)。
我正在尝试使用 nginx 和 django 提供媒体和静态文件,并且正在使用媒体文件进行测试(在 this tutorial 之后)。日志显示它正在尝试获取正确的文件,但它只是没有这样做的权限 (failed (13: Permission denied)
)。全部设置为755,我的nginx.conf和mysite_nginx.conf如下。有什么想法吗?
nginx.conf
worker_processes 1;
error_log /usr/local/etc/nginx/logs/error.log debug;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/etc/nginx/logs/access.log main;
sendfile on;
keepalive_timeout 65;
index index.html index.php;
include /usr/local/etc/nginx/sites-enabled/mysite_nginx.conf;
}
我的网站_nginx.conf
upstream django {
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
server {
listen 8000;
server_name localhost;
root /var/www/;
access_log /usr/local/etc/nginx/logs/default.access.log main;
location / { } #go to default index.html
location /media/ {
alias /Users/meep_me/Desktop/ram_stuff/combining/box/mysite/media/; # your Django project's media files
}
location /static/ {
alias /Users/meep_me/Desktop/ram_stuff/combining/box/mysite/static/; # your Django project's static files
}
location /other {
uwsgi_pass django;
include /Users/meep_me/Desktop/ram_stuff/combining/box/mysite/uwsgi_params; # the uwsgi_params file you installed
}
}
warath-coder 在评论中提到了修复。我忘记明确确保 每个 单个文件夹实际上设置了 +x 位。通过并找到没有解决问题的那个。
/Users/meep_me/Desktop/ram_stuff/combining/box/mysite/media/
:是否每个文件夹都设置了 +x
位权限(通常需要 list/access 和 folder/subfolder)?
我已经花了很多很多时间调试它,但还没有完全找到解决方案。我已经尝试应用来自十几个相关线程的解决方案,但 none 解决了问题(或者我实施了错误的解决方案)。
我正在尝试使用 nginx 和 django 提供媒体和静态文件,并且正在使用媒体文件进行测试(在 this tutorial 之后)。日志显示它正在尝试获取正确的文件,但它只是没有这样做的权限 (failed (13: Permission denied)
)。全部设置为755,我的nginx.conf和mysite_nginx.conf如下。有什么想法吗?
nginx.conf
worker_processes 1;
error_log /usr/local/etc/nginx/logs/error.log debug;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/etc/nginx/logs/access.log main;
sendfile on;
keepalive_timeout 65;
index index.html index.php;
include /usr/local/etc/nginx/sites-enabled/mysite_nginx.conf;
}
我的网站_nginx.conf
upstream django {
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
server {
listen 8000;
server_name localhost;
root /var/www/;
access_log /usr/local/etc/nginx/logs/default.access.log main;
location / { } #go to default index.html
location /media/ {
alias /Users/meep_me/Desktop/ram_stuff/combining/box/mysite/media/; # your Django project's media files
}
location /static/ {
alias /Users/meep_me/Desktop/ram_stuff/combining/box/mysite/static/; # your Django project's static files
}
location /other {
uwsgi_pass django;
include /Users/meep_me/Desktop/ram_stuff/combining/box/mysite/uwsgi_params; # the uwsgi_params file you installed
}
}
warath-coder 在评论中提到了修复。我忘记明确确保 每个 单个文件夹实际上设置了 +x 位。通过并找到没有解决问题的那个。
/Users/meep_me/Desktop/ram_stuff/combining/box/mysite/media/
:是否每个文件夹都设置了 +x
位权限(通常需要 list/access 和 folder/subfolder)?