Django using Nginx to serve static content

回眸只為那壹抹淺笑 提交于 2019-12-02 13:12:08

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!