Django static files with nginx and unicorn -


i'm trying deploy django application vps. followed several tutorials , issue i'm having can't static files show up. below can find structure of files on vps.

  • virtual env: /opt/myapps/
  • django project: /opt/myapps/uniprogress/
  • static files: /opt/myapps/uniprogress/static/

nginx config: /etc/nginx/sites-available/uniprogress

server {     server_name 188.xxx.xxx.93;      access_log off;      location /static/ {         alias /opt/myapps/uniprogress/static/;     }      location / {         proxy_pass http://127.0.0.1:8001;         proxy_set_header x-forwarded-host $server_name;         proxy_set_header x-real-ip $remote_addr;         add_header p3p 'cp="all dsp cor psaa psda our nor onl uni com nav"';     } } 

and in django settings.py:

# build paths inside project this: os.path.join(base_dir, ...)  import os base_dir = os.path.dirname(os.path.dirname(__file__))  # template dirs  template_dirs = (     os.path.join(settings_path, 'templates'), )  # static files (css, javascript, images) # https://docs.djangoproject.com/en/1.6/howto/static-files/  static_root = '/opt/myapps/uniprogress/static/' static_url = '/static/' 

i used: python manage.py collectstatic still static files won't show up.

update tutorial used can found @ digital ocean.

i double checked files exist on server.

also can access static files like: http://188.xxx.xxx.93/static/css/bootstrap.css.

but in source code http://188.xxx.xxx.93:8001/, links static files using port.

that means: <link href="/static/css/bootstrap.css" rel="stylesheet">

so tries find bootstrap.css @ http://188.xxx.xxx.93:8001/static/bootstrap.css , file doesn't exist(have remove post make work).

to serve static files in nginx level

server { server_name 188.xxx.xxx.93;  access_log off;  location ~ ^/(static)/  {   #  root:- static files path   #  alias /opt/myapps/uniprogress/static/;      root /opt/myapps/uniprogress/static/; }  location / {     proxy_pass http://127.0.0.1:8001;     proxy_set_header x-forwarded-host $server_name;     proxy_set_header x-real-ip $remote_addr;     add_header p3p 'cp="all dsp cor psaa psda our nor onl uni com nav"'; } } 

now static files serve nginx.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -