I have a django app, python 2.7 with gunicorn and nginx.
Nginx is throwing a 403 Forbidden Error
, if I try to view anything in my static
folder @:
JavaScript
x
2
1
/home/ubuntu/virtualenv/myapp/myapp/homelaunch/static
2
nginx config(/etc/nginx/sites-enabled/myapp
) contains:
JavaScript
1
24
24
1
server {
2
listen 80;
3
server_name *.myapp.com;
4
access_log /home/ubuntu/virtualenv/myapp/error/access.log;
5
error_log /home/ubuntu/virtualenv/myapp/error/error.log warn;
6
connection_pool_size 2048;
7
8
fastcgi_buffer_size 4K;
9
fastcgi_buffers 64 4k;
10
11
root /home/ubuntu/virtualenv/myapp/myapp/homelaunch/;
12
13
location /static/ {
14
alias /home/ubuntu/virtualenv/myapp/myapp/homelaunch/static/;
15
}
16
17
location / {
18
proxy_pass http://127.0.0.1:8001;
19
proxy_set_header Host $host;
20
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
21
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
22
}
23
}
24
error.log contains:
JavaScript
1
2
1
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/"
2
access.log contains
JavaScript
1
3
1
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"
2
xx.xx.xx.xxx - - [24/Nov/2013:23:02:07 +0000] "-" 400 0 "-" "-"
3
I tried just viewing say a .css
file in /static/
and it throws an error like this in source:
JavaScript
1
8
1
<html>
2
<head><title>403 Forbidden</title></head>
3
<body bgcolor="white">
4
<center><h1>403 Forbidden</h1></center>
5
<hr><center>nginx/1.1.19</center>
6
</body>
7
</html>
8
Advertisement
Answer
It appears the user nginx is running as (nginx?) is missing privileges to read the local file /home/ubuntu/virtualenv/myapp/myapp/homelaunch/static/img/templated/home/img.png
. You probably wanna check file permissions as well as permissions on the directories in the hierarchy.