Portal Home > Knowledgebase > Dedicated Server - Linux > Compressing all web pages with mod_deflate - Apache

Compressing all web pages with mod_deflate - Apache


The mod_deflate module allows the Apache2 web service to compress files and deliver them to clients (browsers) that can handle them. With mod_deflate you can compress HTML, text or XML files by up to 70% of their original sizes. Thus, saving you server traffic and speeding up page loads.


  1. Make sure that mod_deflateis enabled on your server. Your server should have it enabled by default. If the following command returns a line with a "#" at the beginning you will have to remove(uncomment) the "#" character using vi or the perl command below:
    grep 'mod_deflate' /etc/httpd/conf/httpd.conf

    If the result was LoadModule deflate_module modules/mod_deflate.so, you can continue. If the result was #LoadModule deflate_module modules/mod_deflate.so, please run the following command:

    perl -pi -e 's/# LoadModule mod_deflate/LoadModule mod_deflate/g' /etc/httpd/conf/httpd.conf
  2. Now that we have verified that mod_deflateis in fact being loaded by Apache, we must configure the module. First, backup your existing conf file in case you need to revert back:
    cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak 
  3. Using vi, we will edit our Apache conf file and add the following lines at the very bottom of the file, making sure they are separated from any other configurations:
    vi /etc/httpd/conf/httpd.conf
     # Deflate output configuration
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/x-javascript application/xml application/xhtml+xml application/rss+xml

    BrowserMatch ^Mozilla/4 gzip-only-text/html

    BrowserMatch ^Mozilla/4\.0[678] no-gzip
  4. Save your file. Now, we need to check that Apache likes our changes using the apachectl command:
    /usr/sbin/apachectl -t
  5. You should see a Syntax OK message. If not, please check your file to make sure you modified the file correctly. Next, we need to restart apache using the same apachectl command:
    /usr/sbin/apachectl graceful

You have now enabled mod_deflate on your server! You can see whether the changes are in effect using the following tool at http://whatsmyip.org/mod_gzip_test/.

Was this answer helpful?

Print this Article Print this Article

Also Read

Powered by WHMCompleteSolution