Ac3a03edda7a0aafee03bd82d72510ce3c7d5e1e
By:
dilmac

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

March 8, 2015 3.1k views
Django Nginx Ubuntu

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:

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

/etc/init/gunicorn.conf

exec gunicorn \
--name=bichonproject \
--pythonpath=rootproject \
--bind=0.0.0.0:9000 \
--config /etc/gunicorn.d/gunicorn.py \
bichon_project.wsgi:application

/etc/nginx/sites-enabled/django

# 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; 
}
setting.py

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

CRISPYTEMPLATEPACK = 'bootstrap3'

Another issue it only work when I run:

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

using Ubuntu Django on 14.04 and the IPAddress 178.62.73.238

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: setting.py file under bichon_project and main is home app.

Any help very appreciate.

Thanks

1 Answer

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.

Have another answer? Share your knowledge.