我正在使用 nginx 来提供我的 django 静态文件。在浏览器中,我可以看到它们已加载,base.css、login.css、responsive.css 的状态均为 200,我可以单击它们并查看它们的内容。
问题是它们似乎没有在 html 中应用。 html 看起来仍然没有应用任何 css 格式。 nginx 日志中没有错误,chrome 中的网络选项卡中也没有错误。我试过 chrome 和 firefox
使用 Django 2.2.4
相关nginx配置
server {
listen 8000;
server_name 127.0.0.1;
location /static/ {
autoindex on;
alias /home/ubuntu/<SECRET_PATH>/static/;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/<SECRET_PATH>/dashboard.sock;
}
}
最佳答案
根据您的评论,似乎没有为 CSS 文件返回正确的 MIME 类型。在您的 NGINX conf 中,它通常位于 /etc/nginx/nginx.conf
,确保您已包含如下 mime:
包含“/etc/nginx/mime.types”;
并且在您的 mime 中,确保为 CSS 文件设置了正确的 mime 类型。
关于css - 加载后未应用 Django admin css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57488712/