一次css页面加载异常的折腾

1       原始需求

近期在搭建平台,因多域名会分割流量,所以希望将类似

ansible.178linux.com  salt.178linux.com qa.178linux.com 这些平台整合为一个平台,所示如下

ansible.178linux.com =è www.178linux.com/doc/ansible

salt.178linux.com =è www.178linux.com/doc/salt

qa.178linux.com =è www.178linux.com/doc/qa

以些方式最大程度提高平台整体权重。整合过程中出现一个css页面加载异常问题特总结分享

2       问题回放

一次css页面加载异常的折腾

如图: 右浏览器页面css,js,图片等样式无法加载,显示丑陋,

Chrome F12 debug追踪后发现有部分样式不加载,但该页面所有请求均能正常请求并被回应,状态值均为200,

2.1     初步怀疑

2.1.1  css,js目录权限问题  失败

这个问题容易解决,验证也不成问题,

# cd /data/webapps/doc

# chown www. ansible -R

2.1.2  样式文件copy遗漏  失败

确保所有样式文件均没有遗漏,

但测试下来仍然样式渲染不正常

2.2     确认所有请求回应数据

没有其它办法,只能对比doc.178linux.com正常请求来逐个请求和回应数据逐一查看,确认每个请求和回应的数据是否全部都一样.经仔细查看果然发现问题了.

1.     部分css.js,能正常被辨别被正常解析为 text/css  text/javascripts,部分只能被解析为text/html

一次css页面加载异常的折腾

2.     查看页面源码并比对发现所有源码是一样的

3.       google  Content-Type: text/html 发现如下几篇文章

https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Configuring_server_MIME_types

http://stackoverflow.com/questions/5413107/headercontent-type-text-css-is-working-in-firefox-and-chrome-but-in-inter 

2.2.1  初步怀疑

2.2.1.1 /etc/nginx/mime.types文件没有定义 css,js解析结构  —失败

和运营环境正常配置的nginx对比后没有异常

2.2.1.2 浏览器缓存或浏览器支持问题失败

一次css页面加载异常的折腾

发现firefox,chrome均有问题,ie正常,但原因还是无从得知

 

3       从源开始

3.1     Nginx配置

server
	{
		listen 80 default;
		server_name www.178linux.com;
		index  index.php index.html;
		root  /data/webapps/;
                access_log /var/log/nginx/access.log;
                error_log /var/log/nginx/error.log;

		error_page   404   /404.html;
		location ~ [^/]\.php(/|$){
			try_files $uri =404;
			fastcgi_pass  127.0.0.1:9000;
			fastcgi_index index.php;
			include fastcgi.conf;
			#include pathinfo.conf;
			}

		location  ~  /doc/ansible/ {
		        index  index.php index.html;
			try_files $uri $uri/ =404;
			fastcgi_pass  127.0.0.1:9000;
			fastcgi_index index.php;
			include fastcgi.conf;
		}

		location /nginx_status {
			stub_status on;
			access_log   off;
		}

		location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
			{
			expires      30d;
			}

		location ~ .*\.(js|css)?$
			{
			expires      12h;
			}


               if (-f $request_filename/index.html){
               		rewrite (.*) $1/index.html break;
  	         }
	       if (-f $request_filename/index.php){
               		rewrite (.*) $1/index.php;
	         }
               if (!-f $request_filename){
        	        rewrite (.*) /index.php;
 		} 

	}
server
	{
		server_name doc.178linux.com;
		index  index.php index.html;
		root  /data/tran/build/html/;
                access_log /var/log/nginx/access.log;
                error_log /var/log/nginx/error.log;

		error_page   404   /404.html;
		location ~ [^/]\.php(/|$){
			try_files $uri =404;
			fastcgi_pass  127.0.0.1:9000;
			fastcgi_index index.php;
			include fastcgi.conf;
			#include pathinfo.conf;
			}

		location /nginx_status {
			stub_status on;
			access_log   off;
		}

		location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
			{
			expires      30d;
			}

		location ~ .*\.(js|css)?$
			{
			expires      12h;
			}


               if (-f $request_filename/index.html){
               		rewrite (.*) $1/index.html break;
  	         }
	       if (-f $request_filename/index.php){
               		rewrite (.*) $1/index.php;
	         }
               if (!-f $request_filename){
        	        rewrite (.*) /index.php;
 		} 

	}

清理思绪,从头再来,几经检查觉得可能性最大的还是nginx的配置问题,从这个点出发再次切入,增加如下配置后刷新再看,问题解决。 

找了一番官网发现没有特别合适的说明,从配置上看我的个人理解是:

Location匹配到字段后将不会继续查找其它匹配字段,因本页面中即有简单的html页面也有css,js等样式在解析过程中找不到对应配置,所以根据配置规则全部解析为html方式,css,js样式以html的方式是无法正常解析,所以导致样式加载异常。

一次css页面加载异常的折腾

 

原创文章,作者:stanley,如若转载,请注明出处:http://www.178linux.com/5215

(0)
stanleystanley
上一篇 2015-06-08 11:09
下一篇 2015-06-11 13:15

相关推荐

  • Linux之查找命令find简介

    查找命令find简介    Linux使用过程中难免会遇到查找功能,类似于Windows中的搜索功能,如果想要找某个文件在什么地方,什么格式的文件等等。在Linux中我们可以使用find、locate、which、whereis等命令。接下来我们就简单说一下如何使用这几个命令查找文件。 一、which which命令的作用是,在PATH变…

    Linux干货 2015-05-18
  • 主从DNS 子域授权 基于域的转发和DNS视图的配置

    先把软件包的安装: yum install bind yum install bind-utils(DNS的查询工具,dig nslookup host) 事先我已经安装好了。 主从DNS的网络拓扑图: 主从DNS配置: 主从DNS服务器的同步可以有:完全区域同步(AXFR)和增量区域同步(IXFR),配置过程中要注意,增量备份时,需要调整区域文件中的SOA…

    Linux干货 2015-08-24
  • linux文件系统

    linux的文件系统:             根文件系统为rootfs(root file system)           &nbsp…

    Linux干货 2015-12-19
  • 纯文本配置还是注册表

    我们知道Unix/Linux下的程序配置文件从来都是纯文本的,你可以自由地修改和查看,他们也没有什么什么XML之类的玩意(参看XML的这两篇文章:一,二),这个最重要的Unix文化(参看Unix传奇下篇)40多年来就这么沿续下来了。我很佩服Microsoft的创新能力,一会儿用INI,一会儿用注册表,一会又是用XML,这就是Windows的编程中那“强大”的…

    Linux干货 2016-08-15
  • 小型网站MYSQL问题一:MyISAM转Innodb的方法

    故事背景:之前公司的数据库存储引擎全部为MyISAM,数据量和访问量都不是很大,也一直没有什么问题。我最近接手一些运维工作,兼DBA,因为业务上面涉及到钱,所以决定换成支持事物的innodb。下面将操作步骤记录以下。 1、导出mydb数据库的表结构 mysqldump -d -uxxx -p mydb &gt…

    Linux干货 2015-12-19
  • 一个删除MySQL大表数据的shell脚本

    #!/bin/bash #为了删除一些特别大的表 dbname=''  #库名 tabname=''  #表名 step='10000' #删除步长 sleeptime=1  #睡眠时间 start_index=30000001 &…

    系统运维 2015-07-16