Speed Webpages Using Mod_Deflate Module On Apache
Mod_deflate module is used with Apache to increase the speed of download. This module can be used with Apache and it will compress the data before sending to the client. It now been installed by default with most flavours. So you can check before you try to install it. Note: Processing takes additional CPU and memory on your server as well as on the client browser.
Below example show how to enable mod_deflate module.
LoadModule deflate_module modules/mod_deflate.so
Append following configuration
AddOutputFilterByType DEFLATE text/html text/plain text/xml
….
…
Above line only compress html and xml files. Here is the configuration from one of my production box:
…
…
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
AddOutputFilterByType DEFLATE text/html
…
…
Close and save the file. Next restart apache web server. All of the above extension file should compressed by mod_deflate:
# /etc/init.d/httpd restart
You can also specify specific directory and enabling compression only for the html files. For example /static/help/ directory:
AddOutputFilterByType DEFLATE text/html
In real life, there are issues with compressing other types of files such as mp3 or images. If you don’t want to compress images or mp3 files, add following to your configuration:
SetOutputFilter DEFLATE
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
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary
Related posts:
- How to find and compress/gzip files in a folder Below the find command is used to compress/gzip files in...
- How To Install Apache Php Mysql in Linux Download three files and save them in /usr/local/src directory. The...
- Apache (httpd.conf) Directives A Quick Look ServerType standalone The option ServerType specifies how Apache should run...
- Cannot restart Apache : Segmentation fault : Apache Down Apache goes down and wont come up if we try...
- How To Disable Apache Directory Listing In your httpd.conf file you should have something like this:...
