Nginx not serving static files for Django app! Help!

July 6, 2015 44.1k views
DigitalOcean Python Django DigitalOcean Articles Deployment

I’ve wasted 2 entire days without any help on this issue. I followed this guide and have started my application on Digital Ocean. It’s a djago app.
The issue is, it is not loading any static file!
My nano /etc/nginx/sites-available/webapp_name file looks like this:

server {

    access_log off;

    location /static/ {
        root /opt/bizkeeda;

My static files are in folder: /opt/appname/static/

My file looks like this:

STATIC_URL = '/static/'

STATICFILES_DIR = '/opt/appname/static/'

STATIC_ROOT = '/opt/appname/static/'

I also tried changing STATIC_ROOT to /opt/appname

On checking url of static files on website, it is:

All 404 errors!
What should I do?

edited by kamaln7
1 comment
  • Look at your Access and Error Logs , in location = /var/log/nginx
    Within which the string to look for is = failed (13: Permission denied)
    If this exists then its a Permission issue - otherwise follow the usual advise as given in other comments here .

5 Answers

Have you run python collectstatic after uploading the app? Can you check if there are any errors in nginx’s error log?

sudo tail -30 /var/log/nginx/error.log

‘location /static/ ’ part at sites-available and STATIC_ROOT at should be same.
For example:

location /static/ {
        alias   /opt/appname/static/;
STATIC_ROOT = '/opt/appname/static/'

after that run:

python collectstatic

Hey Shekhar,

Did you find the solution to this, I am also facing the similar issue for my python flask application. It would be very helpful if you could share the solution that worked for you.

The solution is to either:

1) change the permissions on the django folder so that nginx can read the files


2) move the staticfiles directory to a place where nginx can read. I recommend something like /var/www/staticfiles

You have to restart the gunicorn also you have to restart the nginx after you update the nginx configuration.

sudo service gunicorn restart
*sudo service nginx restart *

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!