Django, static folder and files not load and 502 Bad Gateway nginx/1.4.6(Ubuntu).

Posted March 8, 2015 6k views

Hi all,

I am new with digitalocean, I have loaded all my files to the server unfortunately not working like on own pc. The issues I have are do not reload the static files (CSS, media, Js). I have read all comments some how can’t find the error I had only one but not sure about.

Mapping Project:

├── bichonproject
├── main
│   └── templates
│   └── main
├── static
│   ├── bootstrap
│   │   ├── css
│   │   ├── fonts
│   │   └── js
│   ├── css
│   ├── images
│   ├── js
│   └── media
└── templates


exec gunicorn \
--name=bichonproject \
--pythonpath=rootproject \
--bind= \
--config /etc/gunicorn.d/ \


# Your Django project's media files - amend as required
location /media {
alias /home/django/rootproject/bichonproject/static/media;

# your Django project's static files - amend as required
location /static {
    alias /home/django/root_project/bichon_project/static; 

STATICURL = '/static/'
STATICFILESDIRS = (os.path.join(BASEDIR, "static"),)
TEMPLATEDIRS = (os.path.join(BASE_DIR, "templates"),)


Another issue it only work when I run:

sudo python runserver localhost:9000 after killing server display 502 Bad Gateway nginx/1.4.6(Ubuntu).

using Ubuntu Django on 14.04 and the IPAddress

Last question do I need to create newvenv files before create app? virtualenv newvenv, if yes do I need to add to my root_project?

Note: file under bichon_project and main is home app.

Any help very appreciate.


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

What i have to do is to move static folder to some of /var/www/static_folder because nginx(or user who is connecting from internet) doesnt have rights to access static files in root.