Project

General

Profile

Actions

AbsoLUAtion » History » Revision 6

« Previous | Revision 6/55 (diff) | Next »
icy, 2008-11-05 17:06
fix spelling


AbsoLUAtion - The powerful combo of Lighttpd + Lua

We want to build a central ressource for Lighttpd + Lua as this is one of the biggest advantages Lighttpd has over other webservers. It's 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 httpds 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 they do and how it helps lighty to do stuff you want it to do.

What's 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

external-static

I´ve seen this nice solution somewhere where they host some files locally on their machines. If popularity gets to high, files are too big or for whatever reasons the files are moved to i think it was amazon´s S3 or akamai for faster serving or to cope with high traffic. You still can use your hostname, urls, collect stats from your logs - your users are just redirected with a 302 to the files they ask for.

Request -> check for local copy -> 302 (if not stored locally) -> let users download from a big pipe

Add the following to your lighttpd.conf:

$HTTP["url"] =~ "^/static/[^/]+[.]gif([?].*)?$" { #match the files you want this to work for
  magnet.attract-physical-path-to = ( "/path-to-your/external-static.lua" )
}

Save the following to external-static.lua:

 local filename = lighty.env["physical.path"]
 local stat = lighty.stat( filename )
  if not stat then
   local static_name = string.match( filename, "static/([^/]+)$" )
   lighty.header["Location"] = "http://<new-location-with-big-pipes>/" .. static_name
 return 302
end 

Updated by icy over 15 years ago · 6 revisions