Nginx failing to load CSS and JS files (MIME type error)

Nginx加载静态文件失败的解决方法(MIME type错误)

上线新的页面,需要在nginx上配置路由, 配置完成后发现页面没有正常加载,提示:style.css未加载,因为其MIME类型“text / html”不是“text / css” ; 线下nginx的配置是正常的,因此对比两者配置发现线上的ng的http 部分多了一行

add_header Content-Type 'text/html; charset=utf-8';

将其注释即可;

重启nginx ,刷新后有时正常(两台机器修改了一台),说明已经生效;重启另外一台ng问题得到解决;

其他的解决办法:

配置文件:

/etc/nginx/nginx.conf

user  nginx;
worker_processes ; error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid; events {
worker_connections ;
} http {
include /etc/nginx/mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
#tcp_nopush on; keepalive_timeout ; #gzip on; include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf

server {
listen ;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main; location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

/etc/nginx/mime.types

types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/x-javascript js;
application/atom+xml atom;
application/rss+xml rss;
..........................................
other types here
..........................................
}

放置include /etc/nginx/mime.types;下的位置/ {而不是下http

Nginx failing to load CSS and JS files (MIME type error)的更多相关文章

  1. 在vue项目npm run build后,index.html中引入css和js 报MIME type问题

    问题: 1.在vue项目中,build打包后,index页面打开会报错, MIME type ('text/html') ;报错内容:because its MIME type ('text/html ...

  2. nginx实现动态分离,解决css和js等图片加载问题

    改帖专门为使用nginx,通过nginx把请求转发到web服务器再返回客户端的时候,解决css和js和图片加载不出来的问题. 如果没安装nginx,请访问一下地址进行安装 http://www.cnb ...

  3. nginx 无法加载css/js图片等文件 404 not fund

    刚配置Nginx反向代理,Nginx可能会出现无法加载css.js或者图片等文件,这里需要在配置文件*.conf里面加上如下配置项. location ~ .*\.(js|css|png|jpg)$ ...

  4. JQuery 加载 CSS、JS 文件

    JS 方式加载 CSS.JS 文件: //加载 css 文件 function includeCss(filename) { var head = document.getElementsByTagN ...

  5. html、css、js的命名规范

    最佳原则 坚持制定好的代码规范. 无论团队人数多少,代码应该同出一门. 项目命名 全部采用小写方式, 以下划线分隔. 例:my_project_name 目录命名 参照项目命名规则: 有复数结构时,要 ...

  6. wp加载本地HTML(附带图片,CSS,JS)

    wp加载本地HTML(附带图片,CSS,JS) Windows Phone:Load Local HTML with Img,Css,Js by 唐小崇 http://www.cnblogs.com/ ...

  7. Django2.0引入css、js、img文件

    Django2.0引入css.js.img文件 一.文件结构 二.settings.py的配置 # Static files (CSS, JavaScript, Images) # https://d ...

  8. ASP.NET 打包多CSS或JS文件以加快页面加载速度的Handler

    ASP.NET 打包多CSS或JS文件以加快页面加载速度的Handler, 使用<link type="text/css" rel="Stylesheet" ...

  9. grunt自定义任务——合并压缩css和js

    npm文档:www.npmjs.com grunt基础教程:http://www.gruntjs.net/docs/getting-started/ http://www.w3cplus.com/to ...

随机推荐

  1. Linux下挂载iso文件和配置yum本地源

    Linux的版本: [root@pbn ~]# head -n 1 /etc/issueRed Hat Enterprise Linux Server release 6.1 (Santiago) 1 ...

  2. SharePoint Framework 基于团队的开发(三)

    博客地址:http://blog.csdn.net/FoxDave 用内部包进行开发 由于你的团队在开发客户端解决方案,你很可能构建通用代码库来在项目中重用.在很多情况下这种库包含的代码是内部所有的不 ...

  3. 173zrx个人简介

    码云链接:https://gitee.com/zhrx-617/codes/947dbs2fi5kw3jz8hc0ma74 效果图: 源代码: <html> <head> &l ...

  4. css设置垂直居中方式总结

    方式1:flex布局,display:flex;align-items:center <!DOCTYPE html> <html lang="en"> &l ...

  5. Nim函数调用的几种形式

    Nim函数调用的几种形式 Nim 转载条件:如果你需要转载本文,你需要做到完整转载本文所有的内容,不得删改文内的作者名字与链接.否则拒绝转载. 关于nim的例行介绍: Nim 是一门静态编译型的系统级 ...

  6. linux下ftp权限控制

    需求背景: 1.创建2个账号给联调的系统使用读取我方服务器提供的文件信息.只允许看到限定的目录,对目录下的文件只有只读权限,禁止shell登录. 2.创建一个内部账号提供文件信息,只允许看到限定的目录 ...

  7. L345 大脑复生

    Yale Researchers Build BrainEx Machine to Restore Brain Function After Death Researchers at Yale Uni ...

  8. java中List按指定大小分割

    之前写过的代码,几个月后遇到类似的功能,感觉很熟悉,稍微费些劲也能做到,但是觉得有些不甘.明明之前整理好的为什么要重新做?百度参考其他人的思路感觉不是很顺心,个人原因吧.于是翻箱倒柜找出以前的代码,贴 ...

  9. Python 3 Anaconda 下爬虫学习与爬虫实践 (1)

    环境python 3 anaconda pip 以及各种库 1.requests库的使用 主要是如何获得一个网页信息 重点是 r=requests.get("https://www.goog ...

  10. CCF CSP 201803-3 URL映射

    转载自 https://blog.csdn.net/tigerisland45/article/details/81697594 /* CCF201803-3 URL映射 */ #include &l ...