问题描述
我遵循部署我的django应用程序。我的应用程序正在运行,并且我配置了nginx来为该站点提供服务。一切都很好,除了静态文件在实际静态文件目录的static子目录中。
I am following the instructions in http://senko.net/en/django-nginx-gunicorn/ to deploy my django application. My application is running under gunicorn and I have configured nginx to serve the site. Everything is fine except that the static files are looked inside a 'static' subdirectory of the actual static file directory.
我在nginx配置中有以下静态文件节文件:
I have the following stanza for static files in the nginx configuration file:
location /static {
root /webapps/myproject/project_staticfiles;
}
其中/ webapps / myproject / project_staticfiles是我拥有所有静态文件(我使用manage.py collectstatic将静态文件放在那里)。但是,当在nginx配置中配置的端口访问站点时,它们不会被发现。 error.log显示它们在更深入的目录中查看:/ webapps / myproject / project_staticfiles / static。
where /webapps/myproject/project_staticfiles is the place where I have all the static files (I use manage.py collectstatic to put the static files there). However, they are not found when the site is accessed at the port configured in nginx configuration. The error.log shows that they are looked in a directory deeper: /webapps/myproject/project_staticfiles/static.
确实,当我创建一个新的目录static和把所有的静态文件放在那里,一切都找到。在我的项目settings.py文件中,我有:
Indeed, when I create a new directory 'static' and put all the static files in there, everything is found. In my project settings.py file I have:
STATIC_URL = '/static/'
STATIC_ROOT = '/webapps/myproject/project_staticfiles'
导致这种奇怪行为的设置是什么?
What is the setting that causes this strange behaviour?
推荐答案
我想你正在使用:
location /static {
alias /webapps/myproject/project_staticfiles;
}
如果您阅读,它指出:
location /i/ {
root /spool/w3;
}
root
文件路径中的目录别名
不会,这就是为什么静态
附加到您的根以形成 / webapps / myproject / project_staticfiles / static
root
appends the directory into the filepath, alias
does not, that is why, static
gets appended to your root to form /webapps/myproject/project_staticfiles/static
这篇关于django + gunicorn + nginx wierdness的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!