Nginx部署静态html样式不正确 Resource interpreted as Stylesheet but transferred with MIME type text/plain


将网站部署到 nginx 之后,网页可以打开,但样式全都没有加载,浏览器里按下 F12 键,console 有报错:

Resource interpreted as Stylesheet but transferred with MIME type text/plain

由于 nginx 没有指定 mime type,则默认会以 text/plain 的形式处理,也就是说,浏览器会以纯文本的形式来处理 css 和 js 文件,所以无法正常加载样式。

修改配置文件 nginx.conf, 在 http{ } 中开启下面两行(一般 nginx.conf 文件中默认是有下面的配置的):

include /etc/nginx/mime.types;
default_type application/octet-stream;

重启nginx服务即可。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM