一次css頁面加載異常的折騰

1       原始需求

近期在搭建平臺,因多域名會分割流量,所以希望將類似

ansible.178linux.com  salt.178linux.com qa.178linux.com 這些平臺整合為一個平臺,所示如下

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

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

qa.178linux.com =è www.www58058.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.www58058.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.www58058.com/5215

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

相關推薦

  • Jumpserver 3.0 全新改版 更輕、更快、更便捷

               Jumpserver Wiki                       &…

    系統運維 2016-01-05
  • samba

    Samba 簡介:      Samba是一個能讓Linux系統應用Microsoft網絡通訊協議的軟件,而SMB是Server Message Block的縮寫,即為服務器消息塊 ,SMB主要是作為Microsoft的網絡通訊協議,后來Samba將SMB通信協議應用到了Linux系統上,就形成了現在的Samba軟件?!?/p>

    系統運維 2016-11-01
  • openssl基礎應用

    參考http://www.www58058.com/2704 http://www.williamlong.info/archives/837.html 一、前言 什么是openssl?講openssl之前我們先了解下什么是ssl?ssl是secure socket layer的簡稱,其使用對稱加密解密,非對稱加密解密(公鑰加密解密),單向加密解密結合證書實…

    Linux干貨 2015-09-27
  • 三劍客-sed小結

     sed是一款流編輯器工具,通常我們用來對文本進行過濾與替換操作,特別是當你想要對幾十個配置文件做統一更改時,你會感受到sed的魅力。它一次處理一行內容。處理時,把當前處理的行存儲在臨時緩沖區中,稱為“模式空間”(pattern space),接著用sed命令處理緩沖區中的內容,處理完成后,把緩沖區的內容送往屏幕。接著處理下一行,這樣不斷重復,直到…

    系統運維 2016-07-26
  • 文件查找相關:whereis、find和locate

        本文將對find和locate進行詳細講解 命令簡介 名稱:whereis     功能:定位文件所在的目錄     用法:whereis shell命令     注意:whereis是根據環境變量PATH來查找文件的,而PATH通常設置成存放命令的那些路徑,如/bin、…

    Linux干貨 2016-04-05
  • grep的基本用法詳解

     grep是linux上常用的一個文本處理工具之一。它有著強大的文本處理能力,學會它,可以讓工作更有效率。 一、初識grep   grep: Global search Regular Experssion and Print out line   從名字上也可以直觀的了解到它是基于正則表達式進行全局搜索,并把結果打印到屏幕上來…

    系統運維 2015-05-25
欧美性久久久久