【发布时间】:2011-10-04 18:21:21
【问题描述】:
当谈到使用 django 1.3 提供静态文件的新方式时,我有点生疏了,但是我确信这不是 django 的问题。
我正在尝试在安装了 debian 的云服务器上运行带有 nginx + fastcgi 的 django 应用程序。我们目前只有一台服务器(在我们开发时),并且将寻求使用负载均衡器运行多台服务器以使其更简单一些,但是我实际上无法让 nginx 提供静态文件。
我已经按照各种教程设置 nginx.conf 来提供文件
server {
listen 80;
server_name 127.0.0.1;
location /static {
autoindex on;
root /static;
}
}
以上是 nginx.conf 的摘录。现在无论我将 root 设置为什么,nginx 在尝试访问 http://127.0.0.1/static/ 时都会抛出 404 not found 错误。
文件结构如下:
/home/user/site/project
/home/user/site/static
/home/user/site/templates
Django settings.py 有以下设置为 STATIC_ROOT 和 STATIC_URL
STATIC_ROOT = "/home/user/site/static/"
STATIC_URL = "http://127.0.0.1/static/"
如果有人能指出我们在哪里做这件事的正确方向,那就太棒了。
【问题讨论】:
标签: python django nginx fastcgi static-files