Linux setup steps/Apache content compression
From Nick Jenkins
Setting up Apache content compression:
To enable the required modules; mod_deflate is now used instead of libapache-mod-gzip:
a2enmod deflate
Load the headers module:
a2enmod headers
Then "nano /etc/apache2/sites-available/default", and add this to the end of the file (but inside the <VirtualHost> block) to enable mod_deflate, and turn on logging for it.
# ---------------------------------------------------
# -------------- Enabling Mod_Deflate ---------------
<IfModule mod_deflate.c>
# Compress all content, manually excluding specified file types
# place filter 'DEFLATE' on all outgoing content
SetOutputFilter DEFLATE
# exclude uncompressible content via file type
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip)$ no-gzip
# properly handle requests coming from behind proxies
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
# Keep a log of compression ratio on each request
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog /var/log/apache2/deflate.log deflate
# Properly handle old browsers that do not support compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
# ---------------------------------------------------
Then check above syntax is OK:
apache2ctl -t
Then restart apache:
/etc/init.d/apache2 force-reload
Can then check it is working by accessing some pages, and doing:
tail -f /var/log/apache2/deflate.log
Note: Have to paste this into /etc/apache2/sites-available/ssl too (if have created it), or otherwise just do HTTPS / SSL setup at the end, which makes things easier.
