Thursday, December 14, 2006
mod_gzip for Apache
Apache's mod_gzip provides good compression for server output. I just got it working on my server with little bit of tweaking done in the configuration. I was using the debian server.
Install mod_zip if you don't have it already:
apt-get install libapache-mod-gzip
Load the module mod_gzip: (add this line in httpd.conf or modules.conf)
LoadModule gzip_module /usr/lib/apache/1.3/mod_gzip.so
Look at the example http://schroepl.net/projekte/mod_gzip/config.htm configuration file.
Here is the configurtaion I added:
Look at http://www.debian-administration.org/articles/31 which reports problem with mod_gzip and mod_ssl, so added this line of configuration as well. Add this only if you enabled ssl access for your server.
NOTE: With Apache2 you can use mod_deflate for the gzip compression. To get more details look at
http://httpd.apache.org/docs/2.0/mod/mod_deflate.html
Install mod_zip if you don't have it already:
apt-get install libapache-mod-gzip
Load the module mod_gzip: (add this line in httpd.conf or modules.conf)
LoadModule gzip_module /usr/lib/apache/1.3/mod_gzip.so
Look at the example http://schroepl.net/projekte/mod_gzip/config.htm configuration file.
Here is the configurtaion I added:
<IfModule mod_gzip.c>I had to add the configuration line mod_gzip_item_include uri .* until then I saw only mod_gzip: DECLINED:EXCLUDED In:0 -< Out:0 = 0 pct. in the mod_zip.log.
mod_gzip_on Yes
mod_gzip_can_negotiate Yes
mod_gzip_static_suffix .gz
AddEncoding gzip .gz
mod_gzip_command_version '/mod_gzip_status'
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 500
mod_gzip_maximum_file_size 500000
mod_gzip_maximum_inmem_size 60000
mod_gzip_handle_methods GET POST
mod_gzip_item_exclude reqheader "User-agent: Mozilla/4.0[678]"
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.js$
mod_gzip_item_include file \.css$
mod_gzip_item_exclude mime ^image/
mod_gzip_item_include mime ^text/
# This was very important to get things working
mod_gzip_item_include uri .*
mod_gzip_dechunk Yes
LogFormat "%h %l %u %t \"%V %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}n
pct." common_with_mod_gzip_info2
CustomLog /var/log/apache/mod_gzip.log common_with_mod_gzip_info2
</IfModule>
Look at http://www.debian-administration.org/articles/31 which reports problem with mod_gzip and mod_ssl, so added this line of configuration as well. Add this only if you enabled ssl access for your server.
<VirtualHost *:443>
<IfModule mod_ssl.c>
...
</IfModule>
<IfModule mod_gzip.c>
mod_gzip_on No
</IfModule>
</VirtualHost>
NOTE: With Apache2 you can use mod_deflate for the gzip compression. To get more details look at
http://httpd.apache.org/docs/2.0/mod/mod_deflate.html