简体   繁体   中英

Django using Nginx to serve static content

I am trying to configure nginx to serve the static content for my django project on a remote VPS. I'm using the following configuration for my nginx instance:

server {
    server_name myVPSip;

    access_log off;

    location /static/ {
        alias /usr/local/pcat/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"';
    }
}

I created the config file in ../nginx/sites-available/ , linked it to /sites-enabled/ , and restarted nginx however when I hit myip:8001/static I get a django 404.

You shouldn't access your website by 123.123.123.123:8001 because that's the port django is using. You are supposed to access 123.123.123.123 (that is port 80) where nginx is running.

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