Django使用Nginx来提供静态内容 [英] Django using Nginx to serve static content

查看:158
本文介绍了Django使用Nginx来提供静态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置nginx来为远程VPS上的django项目提供静态内容。我正在为我的nginx实例使用以下配置:

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"';
    }
}

我在 ../ nginx / sites-available / ,将其链接到 / sites-enabled / ,然后重新启动nginx,但是当我点击 myip:8001 / static 我得到一个django 404。

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.

推荐答案

因为这是django正在使用的端口,请访问您的网站 123.123.123.123:8001 。您应该访问nginx正在运行的 123.123.123.123 (即端口80)。

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.

这篇关于Django使用Nginx来提供静态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆