获取“403访问被拒绝”错误,而不是服务文件(使用django,gunicorn nginx)
我正在尝试使用nginx从django提供私人文件。 对于X-Access-Redirect设置,我遵循以下指南
http://www.chicagodjango.com/blog/permission-based-file-serving/
这是我的网站configuration文件(/ etc / nginx / site-available / sitename):
server { listen 80; listen 443 default_server ssl; server_name localhost; client_max_body_size 50M; ssl_certificate /home/user/site.crt; ssl_certificate_key /home/user/site.key; access_log /home/user/nginx/access.log; error_log /home/user/nginx/error.log; location / { access_log /home/user/gunicorn/access.log; error_log /home/user/gunicorn/error.log; alias /path_to/app; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://127.0.0.1:8000; proxy_connect_timeout 100s; proxy_send_timeout 100s; proxy_read_timeout 100s; } location /protected/ { internal; alias /home/user/protected; } }
然后,我尝试在我的django视图中使用以下来testing下载:
response = HttpResponse() response['Content-Type'] = "application/zip" response['X-Accel-Redirect'] = '/protected/test.zip' return response
但不是我得到的文件下载:
403禁止
nginx的/ 1.1.19
请注意:我已经从configuration文件中删除了所有的个人数据,所以如果有任何明显的错误与我的错误没有关系,可能是为什么。
我的nginx错误日志给了我下面的内容:
**2012/09/18 13:44:36 [error] 23705#0: *44 directory index of "/home/user/protected/" is forbidden, client: 80.221.147.225, server: localhost, request: "GET /icbdazzled/tmpdir/ HTTP/1.1", host: "www.icb.fi"**
你应该使用root :
location /protected/ { internal; root /home/user; }
而不是你的alias :
location /protected/ { internal; alias /home/user/protected; }