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/
Look at the example configuration file.

Here is the configurtaion I added:
<IfModule mod_gzip.c>
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
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.
Look at 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 mod_gzip.c>
mod_gzip_on No

NOTE: With Apache2 you can use mod_deflate for the gzip compression. To get more details look at

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?