Jeff Barr's Blog

Things I Like..

Enabling Mod_gzip

Glenn asked me how to enable gzip under Apache, so I figured I would write this post so that everyone could benefit.

To start, mod_gzip has to be compiled in to Apache. This is a stable module, last updated in late 2002. It is possible that it is already installed, so let’s check and see.

Checking for mod_gzip

Let’s check to see if mod_gzip is already installed. Visit and enter a URL that will be served from your server. Hit the Submit button and await the response. Scroll down to the section labeled HTTP Response Header, and then look for the line labeled “Server:”. My Server line includes the following text (I added the bold-facing):

Apache/1.3.29 (Unix) PHP/4.3.6 mod_gzip/ mod_throttle/3.1.2

As you can see from the bolded text, I already have modgzip installed. If your server has modgzip installed, consider yourself lucky (maybe even buy a lottery ticket), and skip down to the section labeled “Configuring mod_gzip.”

Installing mod_gzip

If you do not have modgzip installed, then you have to install it. The exact procedure for doing this will vary depending on the Apache configuration and operating system. I installed Apache using Apache Toolbox, and simply checked the modgzip entry in the appropriate menu. Go ahead and install it as appropriate (there’s no way I can know enough about your system to say any more than this), and then come back here.

Configuring mod_gzip

Now you need to add some entries to your Apache configuration file. On my system this file is called httpd.conf. You will need the following entries: mod<em>gzip</em>on Yes mod<em>gzip</em>minimum<em>file</em>size 300 mod<em>gzip</em>maximum<em>file</em>size 0 mod<em>gzip</em>maximum<em>inmem</em>size 100000 mod<em>gzip</em>keep<em>workfiles No mod</em>gzip<em>temp</em>dir /tmp mod<em>gzip</em>item<em>include mime ^text/.* mod</em>gzip<em>item</em>include mime ^application/postscript$ mod<em>gzip</em>item<em>include mime ^application/ms.*$ mod</em>gzip<em>item</em>include mime ^application/vnd.<em>$ mod<em>gzip</em>item<em>exclude mime ^application/x-javascript$ mod</em>gzip<em>item</em>exclude mime ^image/.</em>$

After you have you configuration set, restart Apache and your feeds should now be compressed. If you get any error messages when you restart Apache, double-check to make sure that mod_gzip is installed.

Final Zip Tips

You may find it necessary to make sure that certain files or file types are not compressed by modgzip. For example, I have several dynamic pages on Syndic8. The pages can product incremental output for several minutes, usually while they munch on a long list of submitted feeds. By default, modgzip would wait until pages like these have finished, and the output would appear all at once (after several minutes) instead of incrementally. To make sure that this doesn’t happy, simply tell mod*gzip not to process these files by adding the following line to your configuration file: mod</em>gzip<em>item</em>exclude file suggest.php$

That’s about it. Post a comment if you have any questions about this.