前言
部署项目到nginx
环境的时候遇到一个问题:nginx
文件响应类型不对导致浏览器css
解析失败,这篇文章做一个记录。
原因
- 因为
nginx
默认返回的mime
类型是application/octet-stream
配置nginx
在nginx
的配置里面引入mine.types
文件。
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
root html;
index index.html index.htm;
}
}