a-Column

【UNIX】mod_gzipインストール

使用するソース:mod_gzip-1.3.26.1a.tgz

$ tar xvfz mod_gzip-1.3.26.1a.tgz
$ cd mod_gzip-1.3.26.1a
$ APXS=/usr/sbin/apxs make
$ su
# APXS=/usr/sbin/apxs make install

(注意)
APXS: Command not found となる際には、shで%を$になっている
事を確認してみてください。もしくはshと打つ事で確認できます。

以上でインストールされますが、このときに既存の「httpd.conf」が「httpd.conf.bak」にリネームされて、あたらしい「httpd.conf」が出来るので注意してください。もちろん、新しい「httpd.conf」を削除して、「httpd.conf.bak」を「httpd.conf」に戻しても平気です。
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
_result}n In:%{mod_gzip_input_size}n Out:%{mod_gzip_output_
size}n: %{mod_gzip_compression_ratio}npct." gzip_info
CustomLog /var/log/httpd/gzip_log gzip_info
mod_gzip_on Yes
mod_gzip_can_negotiate Yes mod_gzip_static_suffix .gz AddEncoding gzip .gz mod_gzip_update_static No
mod_gzip_dechunk Yes
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 300
mod_gzip_maximum_file_size 0
mod_gzip_maximum_inmem_size 60000
mod_gzip_temp_dir /tmp
mod_gzip_handle_methods GET POST
mod_gzip_item_include mime ^application/x-httpd-cgi
mod_gzip_item_include mime ^application/x-httpd-php
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^httpd/unix-directory$
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 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 mime ^image/.*
mod_gzip_item_exclude file \.css$
mod_gzip_item_exclude file \.js$
mod_gzip_min_http 1001
</IfModule>

httpd.confを編集したら、Apacheを再起動します。

本当に圧縮されているかどうか確認します。サイトを表示したあとに、上記通りの設定なら、「/var/log/httpd/gzip_log」が出来ています。

192.168.0.2 - - [02/Mar/2003:22:36:18 +0900] "GET / HTTP/1.1"
200 4617 mod_gzip:DECHUNK:OK In:10245 Out:4617: 55pct.
こんな感じのログが吐き出されています。In:〜が元のサイズ、Out:〜が圧縮後のサイズ、〜pct.が圧縮率です。この例では元が約10.2Kバイト、圧縮後が約4.6Kバイト、圧縮率は55%と言うことです。

ログは取っておく必要もないのですが、このまま取り続けるのならログがローテーションするように、/etc/loglotate.d/apacheに下記を追加しておきます。

/var/log/httpd/gzip_log
{
missingok
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}


server-status のページで下記の一文があるか確認をする。
Server Version: Apache/1.3.31 (Unix) PHP/4.3.8 mod_ssl/2.8.18 OpenSSL/0.9.7d mod_gzip/1.3.26.1a

Last Update : 2005年06月28日 (火) 01:10