Project

General

Profile

AbsoLUAtion » History » Revision 3

Revision 2 (nitrox, 2008-11-05 15:54) → Revision 3/32 (nitrox, 2008-11-05 16:34)

h1. AbsoLUAtion - The powerful combo of Lighttpd + Lua 

 {{>toc}} 

 *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.* 


 h2. Whats needed for this to work? 

 A [[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 

 h2. 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 --with-lua=lua5.1 
 </pre> 

 h2. Links 

 Link collection (Description -> Link). 

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

 h2. 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> 

  ... 

 h2. Small Helpers 

  ... 

 h2. other solutions