Nginx静态文件(css,js)不生效Resource interpreted as Stylesheet but transferred with MIME type text/plain

2019-09-09 15:593937

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。




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



经过研究,发现需要引入mime.types这个文件,什么是MIME TYPES?

The Multipurpose Internet Mail Extensions (MIME) type is a standardized way to indicate the nature and format of a document. It is defined and standardized in IETF RFC 6838. The Internet Assigned Numbers Authority (IANA) is the official body responsible to keeping track of all official MIME types, and you can find the most up-to-date and complete list at the Media Types page.

Browsers often use the MIME type (and not the file extension) to determine how it will process a document; it is therefore important that servers are set up correctly to attach the correct MIME type to the header of the response object.

因此,有了MIME type,浏览器才知道该以何种方式处理文档,通过查阅官方文档,我们知道常用的两种mime type是:

Two primary MIME types are important for the role of default types:

text/plain is the default value for textual files. A textual file should be human-readable and must not contain binary data.

application/octet-stream is the default value for all other cases. An unknown file type should use this type. Browsers pay a particular care when manipulating these files, attempting to safeguard the user to prevent dangerous behaviors.

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


在Nginx的配置文件中指定默认的MIME type,从上面的引用中,我们得知一般指定为application/octet-stream即可,在CentOS7下,修改配置文件/etc/nginx/nginx.conf, 在http{ }中添加下面两行:

include /etc/nginx/mime.types;

default_type application/octet-stream;


service nginx restart



版权声明:本文为CSDN博主「eponia」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。



上一篇: 明日之后红杉镇探索宝箱在哪?明日之后红杉镇宝箱位置

下一篇: 获取当前分类所在顶级分类的子分类列表

XML 地图