Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 gives a 404
eg: which is at /home/daniels/djangoapp/public/css/style.css gives 404

Any idea what's wrong?


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:, server: localhost, request: "GET /static/public/img/background.jpg HTTP/1.1", host: ""

So it seems that it appends the /static/public part from location directive to the root

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 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.

share|improve this question
"/home/daniels/djnagoapp/public/img/static/public/img/background.jpg" Is djnagoapp intentional typo? – Espennilsen Feb 21 '10 at 12:05

4 Answers 4

up vote 4 down vote accepted

Just fixed using this:

location /static/public/ {
    alias /home/daniels/neasoferul/public/;
share|improve this answer
Thanks, I was using root as well and took me about an hour to figure out what was going on. – xamox Jan 20 '12 at 20:14
Ran into the same issue as xamox. :) – Jason Tu Dec 3 '14 at 18:28

I think Nginx associates rules in reverse order: try putting the /static/public part underneath the / rule.

I have this config, which works fine:

# proxy to Apache 2 and mod_python
location / {
    proxy_set_header    Host             $host;
    proxy_set_header    X-Real-IP        $remote_addr;
    proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;

    proxy_pass http://wsgi;
# catch any weird erroneous media locations - it's a sub domain
location /media/ {
    root   /var/www/sites/mysite/static;
share|improve this answer
It doesn't. It uses the most specific location block. If you have location /media and location /media/images and a request for /media/images/logo.png is received then it will always use /media/images, regardless of the order. – Martin Fjordvald Feb 21 '10 at 17:26

Assuming you didn't actually type in sytle.css in the URL but rather style.css then enable the error log: and see which path it's trying to access.

share|improve this answer

You should put your static content in its own subdomain. It's easier to manage and expand later.

share|improve this answer
Agree on that, but in this particular case i have to server the whole stuff just by ip, no domain name available. – daniels Feb 20 '10 at 19:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.