歡迎您光臨本站 註冊首頁

Apache的HTTP壓縮GZIP優化配置

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

Apache的HTTP壓縮GZIP優化配置

來源:FovWeb-網站架構運營|關注互聯網
地址:Apache的HTTP壓縮GZIP優化配置
HTTP壓縮對於純文本內容可壓縮至原大小的40%一下,從而提供60%以上的數據傳輸節約,雖然WEB伺服器會因為壓縮導致CPU佔用的略微上升,但是可以節約大量用於傳輸的網路IO。對於數據壓縮帶來的用戶瀏覽速度提升(讓頁面符合8秒定律),這點總體負載5%-10%上升是非常值得的。畢竟通過數據壓縮會比通過不規範的HTML代碼優化要方便得多。
mod_gzip的安裝:
修改Makefile中的 apxs路徑:然後make make install
配置:mod_gzip+mod_php
LoadModule gzip_module modules/mod_gzip.so

AddModule mod_gzip.c

<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_minimum_file_size 1000
mod_gzip_maximum_file_size 300000
mod_gzip_item_include file \.htm$
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.php$
mod_gzip_item_include file \.php3$
mod_gzip_item_include mime text/.*
mod_gzip_item_include mime httpd/unix-directory
# mod_gzip的臨時工作目錄: mkdir /tmp/mod_gzip; chmod -R 777 mod_gzip
mod_gzip_temp_dir /tmp/mod_gzip
mod_gzip_dechunk Yes
mod_gzip_keep_workfiles No
</IfModule>
mod_gzip和mod_php的配合:不要讓mod_gzip和mod_php使用同一個臨時目錄,php_session存放目錄可以通過 php.ini設置到session.save_path = /tmp/php_sess
mod_gzip和Resin配合:
從resin的郵件列表上查到的:要讓mod_gzip在mod_caucho后載入,否則mod_gzip不起作用
…othr modules
AddModule mod_so.c
AddModule mod_caucho.c
#notice: mod_gzip must load after mod_caucho
AddModule mod_gzip.c
AddModule mod_expires.c

配置:mod_gzip + resin
<IFModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 3000
mod_gzip_maximum_file_size 300000
mod_gzip_item_include file \.html$
mod_gzip_item_include mime text/.*
mod_gzip_item_include mime httpd/unix-directory
mod_gzip_item_include handler caucho-request
</IFModule>

配置:mod_gzip + mod_proxy 反相代理加速並壓縮 IIS
注意要增加預設的文件編碼屬性映射。
AddType text/html .asp
AddType text/html .aspx
<IFModule mod_gzip.c>
AddType text/html .asp
AddType text/html .aspx
mod_gzip_on Yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 3000
mod_gzip_maximum_file_size 300000
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.asp$
mod_gzip_item_include file \.aspx$
mod_gzip_item_include mime text/.*
mod_gzip_item_include mime httpd/unix-directory
mod_gzip_item_include handler proxy-server
</IFModule>
參考資料:
mod_gzip的下載
http://sourceforge.net/projects/mod-gzip/
mod_gzip項目首頁
http://www.schroepl.net/projekte/mod_gzip/
Apache2 中的mod_deflate:壓縮率比mod_gzip略低
http://httpd.apache.org/docs-2.0/mod/mod_deflate.html
模塊化安裝Apache
http://www.chedong.com/tech/apache_install.html
《解決方案》

不錯,要學習一下,對壓縮比高的文件,用戶訪問速度會提高不少,不過也增加了伺服器的cpu負載
《解決方案》

:em03: :em03:

[火星人 ] Apache的HTTP壓縮GZIP優化配置已經有243次圍觀

http://coctec.com/docs/service/show-post-3368.html