通常Webを参照したときは、サーバから情報を全て取得しクライアントでその情報を展開しますが、サーバから情報を取得する際には非圧縮状態で取得されます。この方法ですとダイアルアップ等の回線の細いの場合、サーバから情報を取得する際に非常に時間がかかってしまいます。
mod_gzip を使用すると、サーバ側で配信対象のファイルを圧縮してから配信するという手順を踏むため、テキストファイル(HTMLファイル)のファイル容量も小さくすることができ帯域を節約させ(取得時間が短くなる)ることが可能です。但し弊害もあり、使用する条件として、圧縮をするためにサーバ側のCPUパワーが消費されること、ページを見る側にgzipを解凍するブラウザ環境が必要となります(IE5.x/6.xであれば問題は無い)。
公式サイト : mod_gzip
参考サイト : ZDNet : Apacheにmod_gzipを組み込んで帯域を節約したい
参考サイト : Apacheにmod_gzipを組み込んでHP配信を高速化する
1) Apache は、DSO 化されている事を前提として話を進めます。
% mkdir -p /opt/local/src/mod_gzip
% cd /opt/local/src/mod_gzip
% wget http://www.remotecommunications.com/apache/mod_gzip/src/1.3.19.1a/mod_gzip.c
% su
# /opt/local/apache/bin/apxs -i -c mod_gzip.c2) httpd.conf に mod_gzip の定義を記述し、Apache を再起動します。
# cd /opt/local/apache/conf
# vi httpd.conf
LoadModule gzip_module libexec/mod_gzip.so
AddModule mod_gzip.c
<IfModule mod_gzip.c>
LogFormat "%h %l %u %t \"%r\" %>s %b mod_gzip: %{mod_gzip_compression_ratio}npct." common_with_mod_gzip_info
LogFormat "%h %l %u %t \"%r\" %>s %b mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n Out:%{mod_gzip_output_size}n:%{mod_gzip_compression_ratio}npct." common_with_mod_gzip_info2
CustomLog /opt/local/apache/logs/gzip_log common_with_mod_gzip_info2
mod_gzip_on Yes
mod_gzip_dechunk yes
mod_gzip_minimum_file_size 300
mod_gzip_maximum_file_size 0
mod_gzip_maximum_inmem_size 60000
mod_gzip_keep_workfiles No
mod_gzip_temp_dir /tmp
mod_gzip_item_include mime ^application/x-httpd-cgi
mod_gzip_item_include mime ^application/x-httpd-php
mod_gzip_item_include handler ^perl-script$
mod_gzip_item_include handler ^server-status$
mod_gzip_item_include handler ^server-info$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^httpd/unix-directory$
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include file \.shtml$
mod_gzip_item_include file \.htm$
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.txt$
mod_gzip_item_include file \.php$
mod_gzip_item_include file \.pl$
mod_gzip_item_include file \.cgi$
mod_gzip_item_exclude file \.css$
mod_gzip_item_exclude file \.js$
mod_gzip_min_http 1001
</IfModule>3) 下記の様なログが出力されていれば問題ありません。
xxx.xxx.xxx.xxx - - [26/May/2002:16:28:52 +0900] "GET /me.html HTTP/1.1" 200 1695 mod_gzip: OK In:10709 Out:1695:85pct.
xxx.xxx.xxx.xxx - - [26/May/2002:16:29:08 +0900] "GET /sample_1210.html HTTP/1.1" 200 1688 mod_gzip: OK In:22098 Out:1688:93pct.
mod_gzip で圧縮された状態をグラフ化して見る事ができます。「mgstat」サイトを参照のこと (^o^)丿
1) 設定方法です。
% wget http://wizard.ae.krakow.pl/~mike/download/mgstat-0.10.tar.gz
% gzip -cd mgstat-0.10.tar.gz | tar xf -
% cd mgstat-0.10
% ./configure
% make
% su
# make install
# /usr/local/bin/mgstat -l /opt/local/apache/logs/gzip_log -d \
/opt/local/apache/htdocs/mgstat