Project

General

Profile

AbsoLUAtion » History » Version 3

« Previous - Version 3/30 (diff) - Next » - Current version
nitrox, 2008-11-05 16:34


AbsoLUAtion - The powerful combo of Lighttpd + Lua

We want to build kind of a central ressource for Lighttpd + Lua as this is one of the biggest advantages Ligtthpd has over other webservers. Its useful, handy, simple and sometimes a quite powerful combo which gives you some additional flexibility and offers you solutions to small and big problems other httpd´s can´t solve!

Again we hope you - the users of lighty - support this page by contributing links, code-snippets or simply offer your lua-scripts with small descriptions of what it does and how it helps lighty to do stuff you want it to do.

Whats needed for this to work?

A decent version of Lighttpd + mod_magnet + Lua (v5.0 or better v5.1, your distro´s should have this) http://www.lua.org

How to get it up and running

 ./autogen.sh
 ./configure --your-normal-options-here \
 --with-lua=lua #will check for lua or lua5.x on debian
 ./make
 ./make check #or VERBOSE=1 make check for detailed results
 ./make install

Links

Link collection (Description -> Link).

Code-Snippets

overwrite default mime-type/content-type

Add "magnet.attract-physical-path-to = ( "/path-to/change-ctype.lua" )" to lighttpd.conf and save the following as "change-ctype.lua"

 if (string.match(lighty.env["physical.rel-path"], ".swf")) then
    lighty.header["Content-Type"] = "text/html" 

simple maintenance script

You need three files, maint.up, maint.down and maint.html.
maint.html holds a simple html-page of what you want to display to your users while in maintenance-mode.

Add "magnet.attract-physical-path-to = ( "/path-to-your/maint.lua" )" to your lighttpd.conf, best is global section or within a host-section of your config, e.g. a board/forum/wiki you know a maintenance-mode is needed from time to time. If you want to switch to maintenance-mode, just copy maint.down to maint.lua in your "/path-to-your/" location, and lighty will display your maint.html to all users - without restarting anything - this can be done on-the-fly. Work is done and all is up again? Copy maint.up to maint.lua in your "/path-to-your/" location. Whats maint.up doing? Nothing, just going on with normal file serving :-)

maint.up - all is up, user will see normal pages

-- This is empty, nothing to do.

maint.down - lighty will show the maintenance page -> maint.html

-- lighty.header["X-Maintenance-Mode"] = "1" 
-- uncomment the above if you want to add the header
lighty.content = { { filename = "/path-to-your/maint.html" } }
lighty.header["Content-Type"] = "text/html" 
return 503
-- or return 200 if you want

Small Helpers

...

other solutions

Updated by nitrox about 11 years ago · 3 revisions