Apache Mod Deflate tutorial
Posted: Mon Apr 02, 2012 10:26 pm
I noticed that noone has discussed this topic here in the forum.
Many people (both admins and users) try to compress their websites to optimize the use of bandwidth and in order to speed up the loading proccess. Even google page speed online suggests to use compression. Many people try to do this via php but thats not very good. Best way is to do it directly from apache. This applies for anyone running apache.
I have been using it in my server for more than 6 months. It does work.
Just go to google page speed online and check for example a joomla site before and after you setup the mod deflate. I saw up to 25points difference !
First of all make sure that in your httpd.con you have loaded the mod deflate.
There shoudl be this line somewhere. If not add it !
Ok
Next we will create the deflate.conf
Next paste the following to the conf we have just created and save it.
Restart apache
Done !
Many people (both admins and users) try to compress their websites to optimize the use of bandwidth and in order to speed up the loading proccess. Even google page speed online suggests to use compression. Many people try to do this via php but thats not very good. Best way is to do it directly from apache. This applies for anyone running apache.
I have been using it in my server for more than 6 months. It does work.
Just go to google page speed online and check for example a joomla site before and after you setup the mod deflate. I saw up to 25points difference !
First of all make sure that in your httpd.con you have loaded the mod deflate.
There shoudl be this line somewhere. If not add it !
Code: Select all
LoadModule deflate_module modules/mod_deflate.so
Next we will create the deflate.conf
Code: Select all
vi /etc/httpd/conf.d/deflate.conf
Next paste the following to the conf we have just created and save it.
Code: Select all
<IfModule mod_deflate.c>
#What types must be compressed
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
#What it should not compress
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
#Maximum compression level (even old hardware have no problem with that...)
DeflateCompressionLevel 9
#Handle browsers with known issues
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
#Logging
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
</IfModule>
Restart apache
Code: Select all
service httpd restart
Done !