mod_gzip:Apache的HTTP壓縮最佳化

日期:2008-07-09  作者:喜騰小二  來源:PHPChina



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

...

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

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

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

配置:mod_gzip + mod_proxy 反相代理加速並壓縮 IIS
注意要增加預設的檔案編碼內容對應。
AddType text/html .asp
AddType text/html .aspx

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

參考資料:

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

 

mod_gzip:Apache的HTTP壓縮最佳化:

<<<返回技術中心

技術文章

站內新聞