Ok so i wanted to give nginx a try and while setuping my Django app through FastCGI i encountered a issue. FastCGI is running ok but static files give me 404. Here is my config:
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/default.access.log;
location /static/public {
autoindex on;
index index.html;
root /home/daniels/djangoapp/public;
}
location / {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/home/daniels/djangoapp/djangoapp.sock;
}
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /var/www/nginx-default;
#}
}
Anything that i try to access as http://127.0.0.1/static/public/ gives a 404
eg: http://127.0.0.1/static/public/css/sytle.css which is at /home/daniels/djangoapp/public/css/style.css gives 404
Any idea what's wrong?
LE:
2010/02/20 22:31:42 [error] 3411#0: *3 open() "/home/daniels/djangoapp/public/img/static/public/img/background.jpg" failed (2: No such file or directory), client: 10.0.2.2, server: localhost, request: "GET /static/public/img/background.jpg HTTP/1.1", host: "127.0.0.1"
So it seems that it appends the /static/public
part from location directive to the root
LE2:
Ok, i'm really sorry about the typos, but this was made when i copy & pasted the log and edited the name of the app. What seems to happen is that for /static/public
i have root set to /home/daniels/djangoapp/public
so for http://127.0.0.1/static/public/test.jpg
i was expecting nginx to look for the file at /home/daniels/djangoapp/public/test.jpg
but instead it looks for it at /home/daniels/djangoapp/public/static/public/test.jpg
It seems that it appends an extra /static/public
to the path.
Just fixed using this:
I think Nginx associates rules in reverse order: try putting the /static/public part underneath the / rule.
I have this config, which works fine:
Assuming you didn't actually type in sytle.css in the URL but rather style.css then enable the error log: http://wiki.nginx.org/NginxHttpMainModule#error_log and see which path it's trying to access.
You should put your static content in its own subdomain. It's easier to manage and expand later.