NGINX / Django:提供静态文件时出错403

时间:2015-01-15 07:54:46

标签: python django nginx

我花了很多时间来调试这个,但还没有找到解决方案。我已经尝试应用来自十几个相关线程的解决方案,但没有解决问题(或者我实现了解决方案错误)。

我正在尝试使用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; 
}

mysite_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
    }
}

2 个答案:

答案 0 :(得分:3)

/Users/meep_me/Desktop/ram_stuff/combining/box/mysite/media/:每个文件夹是否都设置了+x位权限(通常需要列出/访问文件夹/子文件夹)?

答案 1 :(得分:1)

解决方案正如warath-coder在评论中提到的那样。我忘了明确确保每个单个文件夹实际上都设置了+ x位。经历并找到一个没有解决问题的人。