Compressing all web pages with mod_deflate - Apache

Overview

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.

Instructions

  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/.

  • 3 Els usuaris han Trobat Això Útil
Ha estat útil la resposta?

Articles Relacionats

How to Move Accounts From One cPanel Server To Another ?

  This tutorial explains a simple, straightforward method for migrating cPanel accounts from...

CentOS 6.3 on Microsoft Hyper-V Server with Linux Integration Services 3.4

Step by Step install of CentOS 6.3 on Microsoft Hyper-V Server with Linux Integration Services...

How to install cPanel on CentOS

Installation Notes A CentOS or Red Hat server that is going to have cPanel installed needs a...

Why is cPanel/WHM not loading?

There are two main reasons why cPanel/WHM isn't loading that we've seen.Brand New ServerIf you...

How do I bind my additional IPs?

These instructions are for CentOS / Fedora specifically.By default, we only binds your first...