Nginx failing to load CSS and JS files (MIME type error)
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)的更多相关文章
- 在vue项目npm run build后,index.html中引入css和js 报MIME type问题
问题: 1.在vue项目中,build打包后,index页面打开会报错, MIME type ('text/html') ;报错内容:because its MIME type ('text/html ...
- nginx实现动态分离,解决css和js等图片加载问题
改帖专门为使用nginx,通过nginx把请求转发到web服务器再返回客户端的时候,解决css和js和图片加载不出来的问题. 如果没安装nginx,请访问一下地址进行安装 http://www.cnb ...
- nginx 无法加载css/js图片等文件 404 not fund
刚配置Nginx反向代理,Nginx可能会出现无法加载css.js或者图片等文件,这里需要在配置文件*.conf里面加上如下配置项. location ~ .*\.(js|css|png|jpg)$ ...
- JQuery 加载 CSS、JS 文件
JS 方式加载 CSS.JS 文件: //加载 css 文件 function includeCss(filename) { var head = document.getElementsByTagN ...
- html、css、js的命名规范
最佳原则 坚持制定好的代码规范. 无论团队人数多少,代码应该同出一门. 项目命名 全部采用小写方式, 以下划线分隔. 例:my_project_name 目录命名 参照项目命名规则: 有复数结构时,要 ...
- wp加载本地HTML(附带图片,CSS,JS)
wp加载本地HTML(附带图片,CSS,JS) Windows Phone:Load Local HTML with Img,Css,Js by 唐小崇 http://www.cnblogs.com/ ...
- Django2.0引入css、js、img文件
Django2.0引入css.js.img文件 一.文件结构 二.settings.py的配置 # Static files (CSS, JavaScript, Images) # https://d ...
- ASP.NET 打包多CSS或JS文件以加快页面加载速度的Handler
ASP.NET 打包多CSS或JS文件以加快页面加载速度的Handler, 使用<link type="text/css" rel="Stylesheet" ...
- grunt自定义任务——合并压缩css和js
npm文档:www.npmjs.com grunt基础教程:http://www.gruntjs.net/docs/getting-started/ http://www.w3cplus.com/to ...
随机推荐
- Android四大组件之Service --- 活动与服务的绑定
Acticity与Service进行通信如何在活动中指挥service去做事情? 这里就借助onBind()方法了比如说,目前我们希望在MyService里提供一个下载功能,然后在活动中可以决定何时开 ...
- PAT甲级 1001 A+B Format
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 1001 A+B Format ( ...
- Beta冲刺前的准备
Beta冲刺前准备 1.讨论组长否重选的议题和结论 经过团队讨论,不重选组长.我们团队在队长的带领下积极完成任务,使得团队项目初具模型.经过alpha阶段,我们的团队从一开始的零散到如今的凝聚,通力合 ...
- Tomcat配置及不依赖IDEA部署web应用
http:tomcat.apache.org 下载tomcat文件包 我使用的tomcat9的版本 Tomcat9014使用的是Servlet4.0 解压即可,目录如下 bin :启动和关闭tomca ...
- centos7:ftp上传文件
ftp> lcd /var/www/sss 上传文件的地址还一种上传方式ftp> passivePassive mode off.ftp> passivePassive mode ...
- 无线局域网(WLAN)
无线局域网根据结构可以分为两大类:有固定基础设施的无线局域网和无固定基础设施的局域网. 有固定基础设施是指网络中已经预先存在了一批固定的数据处理和转发设备,这些固定设备可以通过有线方式连接其他网络或 ...
- python自动生成bean类
近期在学习python,一直在和java做对比,目前没有发现有通过字段自动生成getter setter方法,故此自己写了一个类,可以通过__init__方法传入类名和字段数组,再调用内部的方法,就可 ...
- ssh外网穿透
不同局域网ubuntu如何进行ssh穿透登录不同局域网ubuntu如何进行ssh穿透登录前言一. 建议安装teamview二. openssh服务三. 打开路由器端口映射四.连接@(ubuntu) 前 ...
- 如何将新建的项目完整的提交到gitlab上?
描述: 使用idea开发工具新建了一个项目工程,此时此刻工程没有任何的版本控制,代码存放在本地磁盘中,如果需要直接将项目工程代码提交到gitlab上,该如何操作呢? 因为当前没有版本控制,不能像正常的 ...
- 【5】用vector进行直接插入排序
百分百自己编的程序,越来越觉得编程很好玩了. 但这算是第一次自己用vector这种不是那么无脑的方法编程,只能最多对3个数进行排序wwwww 今天我要回去搬宿舍了,等明天有时间,我一定要把bug找到! ...