Enable gzip compression on OpenBSD’s Apache

    

OpenBSD ships with Apache 1.3.x. It is better, faster, stronger, etc… but it isn’t compression-capable by default (AFAIK). Here are the directions to enable compression for all your Web resources:

# pkg_add mod_gzip-1.3.26.1ap5.tgz
# /usr/local/sbin/mod_gzip-enable
# cp -p /usr/local/share/examples/mod_gzip/mod_gzip.conf.sample \
  /var/www/conf/modules/mod_gzip.conf
# diff -U2 /usr/local/share/examples/mod_gzip/mod_gzip.conf.sample \
  /var/www/conf/modules/mod_gzip.conf
--- /usr/local/share/examples/mod_gzip/mod_gzip.conf.sample     Thu Feb 24 04:20:39 2011
+++ /var/www/conf/modules/mod_gzip.conf Thu Jul 28 16:53:14 2011
@@ -219,10 +219,11 @@
 mod_gzip_item_exclude         reqheader  "User-agent: Mozilla/4.0[678]"
 #
-# JA:   HTML-Dokumente
+# YES:   HTML & PHP
 mod_gzip_item_include         file       \.html$
+mod_gzip_item_include         file       \.php$
 #
 # NO:   include files / JavaScript & CSS (due to Netscape4 bugs)
-mod_gzip_item_exclude         file       \.js$
-mod_gzip_item_exclude         file       \.css$
+#mod_gzip_item_exclude         file       \.js$
+#mod_gzip_item_exclude         file       \.css$
 #
 # YES:  CGI scripts
@@ -233,8 +234,12 @@
 # ===========================
 # YES:  normal HTML files, normal text files, Apache directory listings
-mod_gzip_item_include         mime       ^text/html$
-mod_gzip_item_include         mime       ^text/plain$
+#mod_gzip_item_include         mime       ^text/html$
+#mod_gzip_item_include         mime       ^text/plain$
 mod_gzip_item_include         mime       ^httpd/unix-directory$
 #
+# YES:   include files / JavaScript & MIME text
+mod_gzip_item_include         mime       ^application/x-javascript
+mod_gzip_item_include         mime       ^text/
+#
 # NO:   images (GIF etc., will rarely ever save anything)
 mod_gzip_item_exclude         mime       ^image/
@@ -283,5 +288,5 @@
 # ---------------------------------------------------------------------
 # Create additional log file
-CustomLog                     logs/mod_gzip.log common_with_mod_gzip_info2
+#CustomLog                     logs/mod_gzip.log common_with_mod_gzip_info2
 # (surely you can redefine your normal log file format, but you mal well
 #  keep its format standard compatible for evaluation by standard web
# apachectl stop; sleep 2; apachectl startssl

Compression should now be enabled. Try to talk to the indian:

# telnet www.tumfatig.net 80
Trying 81.56.68.128...
Connected to tumfatig.net.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.tumfatig.net
Accept-Encoding: gzip
User-Agent: MyFingers/2.5

HTTP/1.1 200 OK
Date: Thu, 28 Jul 2011 15:07:00 GMT
Server: Apache
X-Powered-By: PHP/5.2.17
X-Pingback: http://www.tumfatig.net/xmlrpc.php
Content-Type: text/html; charset=UTF-8
Content-Encoding: gzip
Content-Length: 7665
(...)

The “Content-Encoding: gzip” line means that data were compressed before being sent to me.

Another way to check for details is to use Firebug. You’ll be able to verify that HTML, CSS and JavaScript files are compressed. You’ll get things like:

(...)
Content-Type	text/html; charset=UTF-8
Content-Encoding	gzip
Content-Length	5156
(...)
Content-Type	text/css
Content-Encoding	gzip
Content-Length	2153
(...)
Content-Type	application/x-javascript
Content-Encoding	gzip
Content-Length	31675
(...)

I may have used a plugin to compress my WordPress instance and/or compression at the PHP level. But:

  1. Some plugins I found didn’t do the “whole” job and seemed to slow down WordPress ;
  2. Compression at the PHP level wouldn’t help for the other URIs (like Munin, Monit or SOGo) ;
  3. It’s the server’s job to serve files :)
  4. I wanted to know how it was supposed to be done!

That’s All Folks!