using lua wsapi with mini-httpd
01 Sep 2011It took me a while to find out how to use lua wsapi.cgi with mini-httpd. however, getting this to work is quite helpful if you dont need something as huge as apache, e.g. to run some small service.
1. configuring mini-httpd
this is quite straight foward, the only important thing is to set your cgi directory. in my example we want no seperate cgi-bin or something, so we simply configure mini-http to execute cgi scripts in "/". ( see cgipat in the example config )
# Example config for mini_httpd. # Author: Marvin Stark <marv@der-marv.de>
# Uncomment this line for turning on ssl support. #ssl
# On which host mini_httpd should bind? host=localhost
# On which port mini_httpd should listen? port=9999
# Which user mini_httpd should use? user=nobody
# Run in chroot mode? #chroot # yes nochroot # no
# Working directory of mini_httpd. #dir=<work_dir>
# We are the web files stored? # Please change this to your needs. data_dir=/home/username/htdocs/public
# CGI path cgipat=**.cgi
# Which certificate to use? #certfile=<certfile>
# Which logfile to use? logfile=/home/username/logs/mini-httpd.log
# Which pidfile to use? pidfile=/var/run/mini-httpd.pid
# Which charset to use? charset=iso-8859-1
save this as myconfig.conf or whatever name you want to give the file, and adjust the settings ( data_dir, port etc )
2. installing lua wsapi
lua wsapi comes with debian squeeze, so all you need to do is installing the package:
# apt-get install liblua5.1-wsapi1
3. wrapping your lua scripts in wsapi
next thing you will need is your index.cgi :
#!/usr/bin/env lua
require "wsapi.cgi" require "wsapi.request"
function run(wsapi_env)
local function out() local html = [[ hello world ]] coroutine.yield(html) end
local headers = { ["Content-type"] = "text/html" }
return 200, headers, coroutine.wrap(out)
end
wsapi.cgi.run(run)
4. starting mini-httpd
now you can start mini-httpd
#mini-httpd -C myconfig.conf &