Wednesday, December 18, 2013

Enabling http gzip compression (mod_deflate) in apache

Installing apache on linux server took somewhat a bit long time, 'cause many additional libraries need  installation first.

Here is the list:

apr apr-1.5.0.tar.gz
apr-util apr-util-1.5.3.tar.gz
pcre libpcre
zlib zlib
apache (actually I'm using 2.4.6) httpd-2.4.7.tar.gz

Unzip the files and install them in your server. After installing apr, apr-util, libpcre, zlib, goto the unzipped httpd directory and run
./configure --enable-deflate
If you need enable other modules you can specify in the command. Running above command may tip you missing libraries (in my server I miss apr/apr-util/pcre), just install them. When the configuration is done, run
make
make install
Then apache should have been installed.

To enable HTTP gzip compression, modify the httpd config file:
cd /usr/local/apache2vim conf/httpd.conf
Add lines in the config files:
LoadModule deflate_module modules/mod_deflate.so
<IfModule mod_deflate.c>
        SetOutputFilter DEFLATE
        # You can't compress what is already compressed
        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
        # Make proxies work as they should.
        <IfModule mod_headers.c>
                Header append Vary User-Agent
        </IfModule>
</IfModule>

Exit editting and restart apache
bin/apachectl restart

Now your server has enabled gzip compression! You can validate whether you have succeed or not in this website  HTTP gzip compression test .

No comments:

Post a Comment