X

Install mod_deflate on Apache

Mod_deflate is an apache module. Prior to having mod_deflate it was mod_gzip. Post apache 2.0 mod_deflate is used, it provides a slightly better compression than mod_gzip. It allows the size of certain file types to be compressed which in-turn allows clients to be able to download these files faster. This will cause the site itself to load faster for the clients as well as part of the formula for better page ranking. You can read more about mod_deflate on Apache.org.

Requirements:

This guide assumes you already have Apache running as a webserver. If you don’t, please see Install Apache on CentOS

Enable the mod_deflate module

The deflate module is part of the apache core package, so there is no need to compile additional modules, all that is required is to enable in the Apache configuration.

Verify its not already loaded:

# httpd -M 2>&1|grep deflate
#

Edit the main Apache configuration:

nano /etc/httpd/conf/httpd.conf

Un-comment the following line:

LoadModule deflate_module lib/apache/mod_deflate.so

 

Restart apache to confirm the module loaded

service httpd restart

Check for the loaded module again, you should see it return a result

# httpd -M 2>&1|grep deflate
 deflate_module (shared)

Configure mod_deflate

Create a new configuration file:

nano /etc/httpd/conf.d/deflate.conf

Add the following

<filesMatch "\.(js|.css|html|txt)$">
 SetOutputFilter DEFLATE
 </filesMatch>
 DeflateCompressionLevel 7
 DeflateMemLevel 8
 DeflateWindowSize 10

DeflateCompressionLevel – this is the compression level applied, the default is 9, which is the highest level. The higher the compression level the more CPU it will use.
DeflateMemLevel – The amount of memory zlib, the compressing library can use. The default value is also 9, which is the highest.
DeflateWindowSize – The compression window size.  By default the value is 15 which is the highest level.

This will compress .js, .css, .html,  and .txt files. Attempting to compress images will actually return a larger file size so mod_deflate only really provides an advantage on text based files.

Once you have added the configuration settings, you would then just restart Apache to load everything in.

service httpd restart

That is it for adding mod_deflate to Apache.

 

 

 

LinuxAdmin.io
0 0 votes
Article Rating
LinuxAdmin.io:
Related Post