by mars on 2006-09-25 4 Comments
filed in Work with tags ,

Are you attracted by lighttpd 1.4.12's new mod_magnet?

mod_magnet is a solution to the long-standing quandary of complex URL rewriting without Apache's mod_rewrite. Don't be confused by lighttpd's mod_rewrite; that module should really be called mod_url_find_and_replace.

The gotcha: mod_magnet requires Lua, an embedded programming language created in Brazil. This is the same language that lighttpd's mod_cml uses for Cache Meta Language.

I tried installing Lua via DarwinPorts, but it didn't work. Lighttpd would just complain if I tried enabling mod_magnet:


%  /usr/local/sbin/lighttpd -f ~/etc/lighttpd.conf -D
2006-09-24 22:18:05: (plugin.c.213) mod_magnet plugin init failed
2006-09-24 22:18:05: (server.c.577) loading plugins finally failed

After much tinkering, here's how I got mod_magnet working.

Build pkgconfig

Get & unarchive pkgconfig (currently 0.21) from:
http://pkgconfig.freedesktop.org/releases/


%  cd pkg-config-0.21
%  ./configure
%  make
%  sudo make install

Build LUA

Get & unarchive Lua (currently 5.1.1) from:
http://www.lua.org/ftp/


%  cd lua-5.1.1/
%  make macosx
%  sudo make install
%  sudo cp etc/lua.pc /usr/local/lib/pkgconfig/
%  sudo ranlib /usr/local/lib/liblua.a

Build lighttpd

Get & unarchive lighttpd (currently 1.4.12) from:
http://www.lighttpd.net/download/


%  cd lighttpd-1.4.12/
%  ./configure --with-lua
%  make
%  sudo make install

Configure mod_magnet

Now lighttpd should be happy to hook you up with the magnet! Enable mod_magnet in your lighttpd.conf and specify a magnet file in the context that you need it.


server.modules = ( .. "mod_magnet" .. )
magnet.attract-physical-path-to = ("/path/to/url_rewriting_magnet.lua")

See the mod_magnet docs for the official word.

Next Time... LuaFileSystem on OS X

In my next geekerific article, we'll install LuaFileSystem on OS X for filesystem-aware URL rewriting with lighttpd.

4 Responses to “mod_magnet on OS X”

Tony Perrie commented
2007-07-15 at 10:48 AM
Interesting. My Apache setup has grown so ridiculously complex that it would be a good experiment to replace it all with a Lighttpd cluster.
kint commented
2007-07-15 at 10:48 AM
how about doing a sudo port install lighttpd +cml?
Mars commented
2007-07-15 at 10:48 AM
Ports version of lighttpd was not synced with the newest lighttpd release at the time of this writing. Besides, install from source is a good practice for understanding the software & platform.
Will commented
2010-06-07 at 12:29 PM

Thanks!

Leave a Reply

Markdown is in effect.



Everything is here.