简体   繁体   中英

DJANGO: Serving static with NGINX/gunicorn

I can't seem to get static files loading properly with NGINX.

Strangely if I go to [MY-server-IP]:8001 which is the port assigned with gunicorn, The files load

But if I just go to [MY-server-IP] in the browser the page loads but none of the static does.

Here is my nginx settings:

server {
    server_name [MY-IP];

    access_log off;

    location ~ ^ /static/ {
        alias /django-app/static/;
    }

    location /media/ {
         alias /django-app/SENECA-DJANGO/media/;
    }

    location / {
        proxy_pass http://[MY-IP]: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"'; 
    }
  } 

Did you mean to use the “^~” modifier in the static location? Unless it's a typo, you appear to be using a regular expression in your /static/ location anchored to a leading space.

location ^~ /static/ {
    alias /django-app/static/;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM