SQUID+GZIP+IIS的完美結合!
SQUID如果不能搞定GZIP,那麼肯定流量虛高的,是以SQUID高速WEB緩存伺服器的關鍵問題在于搞定GZIP。
以下是執行個體過程
為了原生支援GZIP,4899網通WEB緩存伺服器用了 SQUID3.0 FOR WINDOWS
1.建立SQUID緩存目錄在 d:/newcache 給user使用者以完全控制權限
2. 把squid壓縮包解壓到C槽目錄,進入squid/etc目錄,複制一分,然後重命名把原檔案的.default全去掉
3.開始編輯 squid.conf
a.我們對外用80端口,是以用批量替換 3128 替換為 80
b.搜尋 http_port 80 後面加上 vhost 變成
程式代碼
http_port 80 vhost
icp_port 3130
cache_mem 433M (取記憶體的1/3+100M)
cache_dir aufs d:/newcache 12000 16 256
maximum_object_size 10240 KB
maximum_object_size_in_memory 6000 KB
memory_pools on
memory_pools_limit 100 MB
cache_swap_high 98%
cache_swap_low 90%
error_directory c:/squid/share/errors/Simplify_Chinese
hosts_file c:/windows/system32/drivers/etc/hosts
cache_peer www.4899.com parent 80 0 no-query originserver no-digest name=cache0
cache_peer 125.46.39.22 parent 8080 0 no-query originserver no-digest name=cache1
cache_peer 4899-img.mfcdn.com parent 8080 0 no-query originserver no-digest name=cache2
cache_peer 4899-flash.mfcdn.com parent 8080 0 no-query originserver no-digest name=cache3
cache_peer_domain cache0 www.4899.com 4899wt.4899.com
cache_peer_domain cache1 125.46.39.22
cache_peer_domain cache2 4899-img.mfcdn.com
cache_peer_domain cache3 4899-flash.mfcdn.com
#配置本機squid允許接受通路的域名,請注意name的對應
acl Safe_ports port 80
acl Safe_ports port 81
acl Safe_ports port 3130
http_access allow all
#允許以上端口的代理
期間找到 http_access deny all #掉他
4.建立緩存目錄,修改hosts
通過cmd進入 c:/squid/sbin
squid -z
将建好緩存
squid -i
将squid注冊為系統服務,在服務裡,找到他,設定自動啟動
進入 c:/windows/system32/drivers/etc/ 編輯 hots檔案,将 www.4899.com 指向源伺服器電信ip
61.152.249.77 www.4899.com
5.啟動squid服務,在服務中啟動他
6.為了使squid能響應iis的GZIP,要在源伺服器做一定修改
a.經典的IIS啟用GZIP的教程如下:
複制 C:/Windows/system32/inetsrv/metabase.xml 到另外的備份檔案夾中.
在開始菜單中啟動 Internet 資訊服務(IIS)管理器,右鍵點選“網站”屬性,打開“服務”頁籤,勾選“HTTP 壓縮”的兩個選項。“臨時目錄”和“臨時目錄最大容量”可根據需要自行設定。設定完成後點選确定。
右鍵點選“網站”下方的 “Web服務擴充”,添加一個新的Web服務擴充,擴充名填寫為“HTTP Compression”或其他,都可以。“要求的檔案”添加:c:/windows/system32/inetsrv/gzip.dll ,并勾選“設定擴充狀态為允許”,完成後點選确定。
在開始菜單中運作 notepad C:/Windows/system32/inetsrv/metabase.xml ,打開metabase.xml 檔案,請在任何改動前再次确認該檔案已經備份。
搜尋并找到 metabase.xml 檔案中的 <IIsCompressionScheme 片段中的 HcScriptFileExtensions,依照原有檔案的格式添加你希望進行 HTTP 壓縮的檔案擴充名,靜态檔案HcFileExtensions可添加 JS,CSS 等; 動态檔案 HcScriptFileExtensions 可添加"ASPX""ASMX",如下:
<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/deflate"
HcCompressionDll="%windir%/system32/inetsrv/gzip.dll"
HcCreateFlags="0"
HcDoDynamic
Compression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="FALSE"
HcDynamicCompressionLevel="9"
HcFileExtensions="htm
html
js
css
txt"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
aspx
asmx
dll
exe"
>
</IIsCompressionScheme>
<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/gzip"
HcCreateFlags="1"
HcDoDynamicCompression="TRUE"
HcDoStaticCompression="TRUE"
注意“Compression/deflate”和“Compression/gzip”兩個片段都需要修改。動态壓縮等級,HcDynamicCompressionLevel 建議設定為“9”
如果你的伺服器上某一個Web站點不希望啟用 IIS 壓縮,請運作以下腳本:
cscript. C:/Inetpub/AdminScripts/adsutil.vbs set w3svc/site#/root/DoStaticCompression False
cscript. C:/Inetpub/AdminScripts/adsutil.vbs set w3svc/site#/root/DoDynamicCompression False
如果想增加啟用 HTTP 壓縮的檔案類型,請運作以下腳本:
"" 中為檔案擴充名,别忘了把原有的擴充名加上。
靜态檔案壓縮:
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcFileExtensions "htm" "html" "txt" "doc" "ppt" "xls"
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcFileExtensions "htm" "html" "txt" "doc" "ppt" "xls"
動态檔案壓縮:
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "aspx" "asmx" "dll" "exe" "php"
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "aspx" "asmx" "dll" "exe" "php"
将site#替換為該 Web 站點的 ID。Web 站點的 ID 是什麼到“日志記錄屬性”中看一下日志記錄的“日志檔案名”前面的路徑就知道了。
運作以上腳本前務必備份,運作後再次執行“IISReset”使生效.
現在看一下 HTTP 壓縮後的效果吧:
測試 HTTP 壓縮效果的工具:
<a href="http://www.pipeboost.com/%3Cbr/%3E">http://www.pipeboost.com/</a>
b.做适當修改,以适應squid緩存需要
在開始菜單中運作 notepad C:/Windows/system32/inetsrv/metabase.xml ,打開metabase.xml 檔案,請在任何改動前再次确認該檔案已經備份
HcNoCompressionForHttp10="TRUE"
HcNoCompressionForProxies="TRUE"
上面這倆改成FALSE
然後查找 HcDoDynamicCompression 也要改成 FALSE,這實際上是關閉了動态加速,以4899小遊戲網站配置SQUID+GZIP的經驗,HcDoDynamicCompression="TRUE"時,SQUID緩存動态檔案會出現問題,關了就好了。