Apache Modules mod deflate
From Gentoo Linux Wiki
|
|
|
Main Modules
Addons & Tunnels Tips Configuring Other |
| edit |
[edit] Getting Started
Mod_deflate is included with apache2 and replaces the mod_gzip from apache 1.x. This module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network. This greatly speeds up page load times, especially for people with dialup.
[edit] Configuration
On my server, mod_deflate was already being loaded, but lets check just to make sure.
Make sure this line is uncommented.
| File: /etc/apache2/httpd.conf |
.... LoadModule deflate_module modules/mod_deflate.so .... |
Then add the filters to the end of httpd.conf according to your needs. This will work then for the complete server including vhosts. Of course you can enter this also into a vhost or htaccess-file to enable it only for a certain vhost/folder.
Please note that since Apache 2.2, AddOutputFilterByType has been deprecated. So if you want to compress by mimetype, you have to use FilterDeclare etc:
| File: /etc/apache2/httpd.conf |
.... DeflateFilterNote Ratio ratio DeflateCompressionLevel 9 FilterDeclare COMPRESS FilterProvider COMPRESS DEFLATE resp=Content-Encoding !$gzip FilterProvider COMPRESS DEFLATE resp=Content-Type $text FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-javascript FilterProvider COMPRESS DEFLATE resp=Content-Type $application/.*xml.* FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml FilterChain COMPRESS |
Instead of $text you can use any mime-type. $text simply deflates ALL text/... mimetypes. The other takes care of javascript and xml files which aren't detected as text/xml.
You can also put the directives in a separate file, like /etc/apache2/modules.d/99_mod_deflate.conf so that etc-update goes smoother when you update apache.
You also want to add something similar to this so the compression ratio is shown in your logfiles:
| File: /etc/apache2/modules.d/00_mod_log_config.conf |
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" (%{ratio}n)" combineddeflate
CustomLog /var/log/apache2/access_log combineddeflate
|
Restart Apache to activate your changes.
| Code: Restart apache |
|
/etc/init.d/apache2 restart
|
Now you should have compression working! The logfiles show you something like a (10) behind each entry, meaning that the file was compressed to 10% of its original size.
