0

I am following the instructions in http://senko.net/en/django-nginx-gunicorn/ to deploy my django application. My application is running under gunicorn and I have configured nginx to serve the site. Everything is fine except that the static files are looked inside a 'static' subdirectory of the actual static file directory.

I have the following stanza for static files in the nginx configuration file:

location /static {
    root /webapps/myproject/project_staticfiles;
}

where /webapps/myproject/project_staticfiles is the place where I have all the static files (I use manage.py collectstatic to put the static files there). However, they are not found when the site is accessed at the port configured in nginx configuration. The error.log shows that they are looked in a directory deeper: /webapps/myproject/project_staticfiles/static.

Indeed, when I create a new directory 'static' and put all the static files in there, everything is found. In my project settings.py file I have:

STATIC_URL = '/static/'
STATIC_ROOT = '/webapps/myproject/project_staticfiles'

What is the setting that causes this strange behaviour?

user1487178
  • 83
  • 1
  • 1
  • 10

1 Answers1

1

I think you are looking to use alias:

location /static {
    alias /webapps/myproject/project_staticfiles;
}

If you read the docs on root, it states:

root specifies the document root for the requests. For example, with this configuration:

location  /i/ {   
    root  /spool/w3; 
} 

A request for "/i/top.gif" will return the file "/spool/w3/i/top.gif". You can use variables in the argument.

root appends the directory into the filepath, alias does not, that is why, static gets appended to your root to form /webapps/myproject/project_staticfiles/static

Sanketh Katta
  • 5,961
  • 2
  • 29
  • 30