Turning on compression in Mac OS X Snow Leopard Server’s Apache

Instructions to turn on web page compression in Mac OS X Snow Leopard Server via Mod Deflate

I received a couple of MacMini servers, with Snow Leopard Server installed, as a donation for the site. I went ahead and added them to the server farm as web servers. However, testing showed that no compression of web pages was happening and requests served from those servers were consuming far too much bandwidth. The management software for those servers didn’t seem to allow one to configure mod_deflate to turn on compression.

It’s simple, but I couldn’t find anywhere on the internet any instructions for Mac OS X server specifically and I didn’t want to interfere with the management software. So I took the easiest route and copied my mod_deflate.conf file from my linux based servers over to the MacMinis and put it in the ‘sites’ directory in apache2’s folder.

Here are the contents of the file:

# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIf Request_URI \.js no-gzip

# Make sure proxies don't deliver the wrong content
<IfModule mod_headers.c>
	Header append Vary User-Agent env=!dont-vary

Paste the above code into a file and name it ‘mod_deflate.conf’ and copy the file to ‘/etc/apache2/sites/’.

Update for Mountain Lion Server: Copy the file to ‘/Library/Server/Web/Config/apache2/other/’.

Here is a downloadable copy: mod_deflate.conf

Of course you need to restart apache.