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.
来源:https://stackoverflow.com/questions/24131830/django-using-nginx-to-serve-static-content