Log in Go to the main page Page Discussion History Go to the file list Go to the site toolbox Bookmark and Share

Enable Apache 2.x Content Compression

From RZWiki


Image:Apache-logo-massive.gif

To enable web content compression using mod_deflate on a system running Apache 2.x;

  • If necessary, enable the Apache mod_deflate module with this command: a2enmod deflate
  • Locate the Apache configuration file: httpd.conf or apache2.conf, normally found in either the /etc/httpd/conf/ or /etc/apache2/ directory respectively. Open it in a text editor and if necessary, remove the '#' from the start of this line:
#LoadModule deflate_module modules/mod_deflate.so to have Apache load the mod_deflate module.
  • Then add the following to the end of the file to enable deflate compression (SetOutputFilter DEFLATE) and prevent compression of images, archive files, PDF files (which are already compressed) and executables:
Location /
    SetOutputFilter DEFLATE
    SetEnvIfNoCase Request_URI  \
        \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI  \
        \.(?:exe|t?gz|zip|gz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \
        \.pdf$ no-gzip dont-vary
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    BrowserMatch MSIE force-no-vary
    Header append Vary User-Agent env=!dont-vary
/Location

Contents

Image:accessories-text-editor-v2-medium.png Usage Notes

If you're not sure what version of Apache your running, see the Find Out Which Apache Version Is Running article

You'll note SVG image files are not excluded, this is because they are actually XML files which 'describe' an image.

You can adjust the compression level of mod_deflate using the DeflateCompressionLevel directive. Valid values are in the range between 1 (favours speed over compression) and 9 (favours compression over speed. The default value is 6.

Apache does also support gzip (mod_gzip) but using zlib (mod_deflate) is preferrable as gzip uses the deflate algorithm anyway but is generally slower as it uses larger headers and trailers and a slower integrity check (aka checksum) compared to zlib (mod_deflate) used alone.

HTTP Headers are not compressed.

Compression Client Support

As compression support is optional in the HTTP/1.0 specification (RFC1945) you should assume HTTP/1.0 only capable clients will not support compression (the notable exception being Netscape 4.)

Of lesser importance, the HTTP/1.0 compression Headers are the same as that used in HTTP/1.1 (Accept-Encoding: and Content-Encoding:) however, the supported values are different: x-gzip, x-compress and token. A value of gzip should be considered and handled in the same way as an x-gzip value for future compatibility but again, this may not be implemented on some clients.

Even HTTP/1.1 (RFC2616) capable clients may send/make HTTP/1.0 requests depending on configuration. I've seen this frequently with IE6.

font color=redNote Microsoft Internet Explorer, including v7, does not support any Vary header (related to compression and other HTTP features) value other than User Agent, in isolation. If any other, or more than one value is present in this header, browser caching will not occur and content may not display in external programs launched by IE./font See the Disable Vary Header Insertion By Apache For MSIE Clients and Disable Vary Header Insertion By F5 BigIP for information on how to overcome this issue for these platforms.

Also note Microsoft Internet Explorer v6 and v7 frequently make HTTP/1.0 requests for the reasons described in this Knowledge Base article: http://support.microsoft.com/kb/947513, which also describes how to fix this issue. Keep this in mind when dealing with compression and caching issues with these browsers.

Other potential issues can be found in our Web Applications Troubleshooting article. noinclude/noinclude

Image:accessories-dictionary-medium.png Further Information

deflate and zlib are commonly considered one and the same but they are not, deflate is a compressed data format that forms part of the zlib compression library, as well as the gzip compression library. To confuse matters Apache mod_deflate is actually an implementation of zlib for transfer encoding, not deflate.

Image:icemon-medium.png Related Articles

Take a look at our other How To... articles

See the gzip Compression Overhead and zlib Compression Overhead articles for further information on the overhead created by these compression libraries and detailed data demonstrating how they can actually increase data size.

For more information on zlib visit the zlib website: http://www.zlib.net

For more information on gzip visit the gzip website: http://www.gzip.org

Information on other Linux commands Image:Tux-small.png

Information on F5 BigIP commands Image:F5-logo-small.png

Information on Cisco commands Image:Cisco-logo-small.png

Information on Vyatta commands Image:Vyatta-logo-small.png

Information on Extreme commands Image:Extreme-logo-small.png

Information on Zebra commands

Information on Secure Platform commands

Information on Blue Coat SGOS commands

Information on Nokia IPSO commands


Image:internet-group-chat-small.png We really do appreciate all feedback so please do send your comments, suggestions or corrections to sjiveson#routerzone.eu
(replacing the # with an @)


Site Toolbox:

Personal tools
This page was last modified on 24 June 2010, at 11:53. - This page has been accessed 26 times. - Disclaimers - About RZWiki
Powered by MediaWiki