Project

General

Profile

AbsoLUAtion » History » Version 8

Version 7 (nitrox, 2008-11-05 17:13) → Version 8/30 (icy, 2008-11-05 17:28)

h1. AbsoLUAtion - The powerful combo of Lighttpd + Lua

{{>toc}}

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.

h1. What's needed for this to work?

* A [[DevelSubversion|recent]] [[DevelSubversion|decent]] version of Lighttpd
*
+ [[lighttpd:Docs:ModMagnet|mod_magnet]]
*
+ Lua (v5.0 or better v5.1, your distro´s should have this) http://www.lua.org

h1. How to get it up and running

<pre>
./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
</pre>

h1. Links

Link collection (Description -> Link).

* Bundle css + js files to save some hits and not break browsers parallel download: "lighttpd+mod_magnet+lua":http://www.cakephp.nu/faster-page-loads-bundle-your-css-and-javascript-lighttpd-mod_magnet-lua

h1. 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"
<pre>
if (string.match(lighty.env["physical.rel-path"], ".swf")) then
lighty.header["Content-Type"] = "text/html"
</pre>

*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

<pre>
-- This is empty, nothing to do.
</pre>

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

<pre>
-- 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
</pre>

h1. Small Helpers

...

h1. 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:
<pre>
$HTTP["url"] =~ "^/static/[^/]+[.]gif([?].*)?$" { #match the files you want this to work for
magnet.attract-physical-path-to = ( "/path-to-your/external-static.lua" )
}
</pre>

Save the following to external-static.lua:
<pre>
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
</pre>