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服务即可。

猜你喜欢

转载自www.cnblogs.com/manastudent/p/12960590.html