Problem to get static content with nginx / gunicorn for django application

November 11, 2015 769 views
Applications Nginx Django Deployment Ubuntu


I have followed the tuto provided on digital ocean to deploy my django app:

I followed the instructions but at the end it appeared that the static folder was inaccessible. I looked for solution during the whole day just for this and nothing. Here is all the informations, if you have an idea be free to try :

the tree of the project. It's present inside /opt/myenv/

├── grumblr
│   ├── media
│   │   └── addr-book-photos
│   ├── migrations
│   ├── static
│   │   ├── grumblr_css
│   │   ├── grumblr_image
│   │   └── grumblr_js
│   └── templates
│       └── grumblr
└── webapp

the importants line inside settings.py

STATIC_ROOT = '/opt/myenv/static/'

STATIC_URL = '/static/'

and when I do python manage.py collectstatic a new folder is created inside /opt/myenv/ correctly.

Now for nginx, inside the file /etc/nginx/site-enables/webapp

server_name xxx.xxx.xxx.xxx;

    access_log off;

    location /static {
        alias /opt/myenv/static/;

after that I did the sudo service nginx restart, and I got the confirmation done.

I tried to run everything with the command:

gunicorn webapp.wsgi:application --bind=xxx.xxx.xxx.xxx:8001

and the website worked, but no css or js, no static content.

To check, I put again Debug=True and try to access :

I got the following yellow screen :

Page not found (404)
Request Method: GET
Request URL:
Using the URLconf defined in webapp.urls, Django tried these URL patterns, in this order:
The current URL, static/grumblr_image/logo_profil.png, didn't match any of these.

I'm not sure if it's supposed to follow this url and nginx resolved it after, or if it's completly wrong.

Thank you for all the help you can provide.

Be the first one to answer this question.