Thursday, April 23, 2009

Using mod_negotiation with Lighttpd

Yesterday we finally decided to switch our web servers to Lighttpd 1.5.0
Everything went fine on the test environments until I ran into a problem with Lighty and Apache's mod_negotiation that we are using on some websites.
It turned out that there is no easy solution for a technique like mod_negotiation in Lighttpd, but fortunately Lighty has one very powerful module called Mod_Magnet.

With Mod_Magnet you actually can write your our LUA scripts for use with Lighttpd.
I was eager to try it. And here it comes my first LUA script emulating mod_negotiation and rewriting to a predefined file if nothing was found while "negotiating".

Use it like this:

# set document root for domains
$HTTP["host"] =~ "^(.*)(domain\.com)$" {
magnet.attract-physical-path-to = ( "/usr/local/lighttpd/etc/lighttpd-multiviews-to-php+rewrite.lua" ) # multiviews module

To compile Lighty with LUA support use:
./configure --prefix=/usr/local/lighttpd --with-lua

but before that you should install LUA 5.1