Jam*_*est 0 python django nginx
我试图在生产环境中部署Django应用程序,我似乎无法正确渲染CSS.在我当地的环境中它工作正常.在设置中,我已经设置:
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
Run Code Online (Sandbox Code Playgroud)
在服务器上,我运行collectstatic将文件收集到以下文件夹中:
STATIC_ROOT = '/sites/thetweethereafter.com/public/static'
Run Code Online (Sandbox Code Playgroud)
网络服务器是nginx,我的nginx.conf是:
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name www.thetweethereafter.com;
rewrite ^/(.*) http://thetweethereafter.com/$1 permanent;
}
server {
listen 80;
server_name thetweethereafter.com;
access_log /sites/thetweethereafter.com/logs/access.log;
error_log /sites/thetweethereafter.com/logs/error.log;
location /static {
autoindex on;
root /sites/thetweethereafter.com/public/;
}
location / {
proxy_pass http://127.0.0.1:29000;
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我直接浏览静态文件,我可以没问题.
http://thetweethereafter.com/static/css/styles.css
但是,当我加载引用其中一个文件的页面时,浏览器不会呈现它们.
我不能为我的生活弄清楚我做错了什么.我有很多其他项目以类似的方式设置,它们工作正常.我错过了什么?
检查您的网站索引我注意到css文件被用作"text/plain"而不是"text/css"文件类型.所以问题应该依赖于服务器配置.
Nginx必须知道根据文件扩展名应用哪种mime类型.在新的debian安装上,http部分中有一个include指令,如下所示:
http {
[...]
include /etc/nginx/mime.types;
[...]
}
Run Code Online (Sandbox Code Playgroud)
这应该够了吧.
| 归档时间: |
|
| 查看次数: |
915 次 |
| 最近记录: |