问题描述

最近学习在补前端知识了,使用Nginx做静态内容服务器1。遇到了一个小问题:

Resource interpreted as Stylesheet but transferred with MIME type text/plain: “http://localhost/web-projects/the-html-head/styles/styles.css”

解决方法

若不对于css文件解析进行配置,nginx默认文件都是text/plain类型进行解析2,为此我们需要对此进行
简单配置。将下面这段代码放入到location模块下面,然后重启nginx。记住一定要清理浏览器的缓存

1
2
include mime.types;
default_type application/octet-stream;

参考资料


  1. 1.http://nginx.org/en/docs/beginners_guide.html
  2. 2.https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Configuring_server_MIME_types