ubuntu - Can't serve statics with Nginx on DigitalOcean VPS for Django -


hi trying serve statics using django , nginx on vps project live. settings.py includes following.

base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) static_url = '/static/ static_root = os.path.join(base_dir, 'static', 'static')  media_url = '/media/' media_root = os.path.join(base_dir, 'static', 'media') 

my project folder includes:

static ----static ----static-only ----media ----templates 

in nginx got following:

upstream gunicorn_server { # fail_timeout=0 means retry upstream if failed # return http response (in case unicorn master nukes # single worker timing out). server 127.0.0.1:9000 fail_timeout=0; }  server {  listen   80; server_name example.com; keepalive_timeout 5; client_max_body_size 4g;  access_log /home/projectuser/logs/nginx-access.log; error_log /home/projectuser/logs/nginx-error.log;  location /static/ {     alias   /venv/project/static/static; }  location /media/ {     alias   /venv/project/static/media; } location / {      proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;     proxy_set_header host $http_host;     proxy_redirect off;      if (!-f $request_filename) {         proxy_pass http://gunicorn_server;         break;     }  }  } 

i can't serve static no matter , admin panel css not showing up.

please advise asap.

try changing static , media blocks way:

location /static/ {     root   /venv/project/static; }  location /media/ {     root   /venv/project/static; } 

this way, http://example.com/static/admin/css/dashboard.css searched /venv/project/static/static/admin/css/dashboard.css on filesystem.

p.s. instead of if (!-f $request_filename) it's better use try_files: http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -