EnablingApacheCompression

From MicroFocusInternationalWiki
Jump to: navigation, search

How to Enable gzip Compression with Apache

Zipping up the contents of a web page is a common method of bandwidth conservation. There are many methods to accomplish this, this is one of them. Some file types (graphics, executables, archives, pdfs) do not benefit from compression, and are thus excluded in this scenario.

On OES2 NetWare (6.5 sp7):

  • Open the sys:\apache\conf\httpd.conf file
  • Scroll down the file until you see a series of #LoadModule statments. At the end of this list, add the following:
LoadModule deflate_module modules/deflate.nlm
<Location />
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-var
</Location>
  • Save the file
  • Restart apache

On OES2 Linux (SLES10)

  • Open the /etc/apache2/httpd.conf file
  • after the "Include /etc/apache2/default-server.conf" line add the following:
LoadModule deflate_module /usr/lib/apache2/mod_deflate.so
<Location />
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-var
</Location>
  • Save the file
  • Restart Apache (/etc/init.d/apache2 restart)

How Will I Know If It's Working?

To the browser, this will all be transparent. A packet trace (or packet header viewer if you've got one installed) can verify that the content is being compressed.

The http packet will include a header that looks like this:

Content-Encoding: gzip

Note: Wireshark/Ethereal will automatically unzip the contents for you while you view the packets. Sniffer Pro will show the packets in raw (compressed) form, i.e. it will be garbled text.

--Ncheshire 12:11, 28 November 2007 (MST)