当涉及到使用 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/"
如果有人能为我们指出正确的方向,告诉我们该怎么做,那就太棒了。
最佳答案
root /static
这不应该是 /home/user/site/static
吗?
关于python - 使用 django + fastcgi debian 从 nginx 提供静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6683936/