Xavante
A Lua Web Server with CGILua support

Installing

Xavante follows the package model for Lua 5.1, therefore it should be "installed" in your package.path.

Windows users can use the pre-compiled version of Xavante's binary components (LuaSocket, LuaFileSystem and Rings) available at LuaForge.

Xavante installation is very flexible and is based on three directories:

$BIN - System executables

$LIB - Lua binary libraries

$LUA - Lua libraries

$WEB - Xavante HTTP documents.

The $LUA directory should be part of your package.path and the $LIB directory should be part of your package.cpath. Those directories can be even under the same upper directory if this is convenient, as the following Windows example show.

The typical Unix installation assumes that Lua 5.1 and all the Xavante's dependencies are already installed in the system and uses the command sequence:

./configure
sudo make standalone

This copies the Xavante files to the $LUA based directories and the startup file xavante_start.lua to the $BIN directory. The startup file looks for an optional environment variable XAVANTE_INIT ir a xavante_init.lua configuration file to define the Lua Path, the C Path and the system libray extension name (dll or so for example).

Unix Installation Example

An example of a Unix Xavante installation is shown below with the list of included files and where the source for those files can be found in LuaForge. Please check each module documentation for details on how to install it.

$BIN -- /usr/local/bin by default
    xavante_start.lua

$LIB  -- /usr/local/lib/lua/5.1 by default
	lfs.so            -- LuaFileSystem
	/mime
	    core.so       -- LuaSocket
	rings.so          -- Rings
	/socket
	    core.so       -- LuaSocket

$LUA  -- /usr/local/share/lua/5.1 by default
	/cgilua           -- CGILua
	cgilua.lua        -- CGILua        
	copas.lua         -- Copas
	coxpcall.lua      -- Xavante
	ltn12.lua         -- LuaSocket
	mime.lua          -- LuaSocket
	sajax.lua         -- Xavante
	/socket           -- LuaSocket
	socket.lua        -- LuaSocket
	stable.lua        -- Rings
	/xavante          -- Xavante
	xavante.lua       -- Xavante

Configuring

The file $LUA/xavante/config.lua defines the Xavante default configuration using the xavante.httpd.handle_request to chain a series of handlers.

A typical config.lua using xavante.httpd.handle_request uses the format below

require "xavante.httpd"

require "xavante.vhostshandler"
require "xavante.urlhandler"
require "xavante.indexhandler"
require "xavante.filehandler"
require "xavante.cgiluahandler"


xavante.httpd.handle_request = xavante.vhostshandler {
	[""] = xavante.urlhandler {
		["/"] = xavante.indexhandler ("/cgi/index.lp"),
		["/cgi/"] = xavante.cgiluahandler.makeHandler (XAVANTE_WEB),
		["/img/"] = xavante.filehandler (XAVANTE_WEB.."/img"),
	}
}

xavante.httpd.register ("*", 8080, "Xavante 1.3")

Another approach for Xavante configuration is to use the xavante.HTTP constructor. It defines virtualhosts for each site that it is running. Each virtualhost can define a set of rules for it. Each rule matches a URL pattern with a handler. Xavante currently offers a file handler, a redirect handler and a CGILua handler for general files, URL remapping and CGILua scripts respectively.

A typical config.lua using xavante.HTTP uses the format below

require "xavante.filehandler"
require "xavante.cgiluahandler"
require "xavante.redirecthandler"

-- Define here where Xavante HTTP documents scripts are located
local webDir = XAVANTE_WEB

local simplerules = {
    { -- URI remapping example
    match = "/",
    with = xavante.redirecthandler,
    params = {"index.lp"}
    }, 

    
    { -- filehandler example
    match = "/*",
    with = xavante.filehandler,
    params = {baseDir = webDir}
    },
     
    { -- cgiluahandler example
    match = {"/*.lp", "/*.lua"},
    with = xavante.cgiluahandler.makeHandler (webDir)
    },
}

-- Displays a message in the console with the used ports
xavante.start_message(function (ports)
    local date = os.date("[%Y-%m-%d %H:%M:%S]")
    print(string.format("%s Xavante started on port(s) %s",
      date, table.concat(ports, ", ")))
  end)

xavante.HTTP{
    server = {host = "*", port = 8080},
    
    defaultHost = {
    	rules = simplerules
    },
}

Note the use of webDir both to set the base directory for the file handler and for the CGILua scripts. These paths should contain the desired directories if you are not using the Kepler structure.

To use virtual hosts with Xavante, the call to xavante.HTTP would be changed to something like

xavante.HTTP{
    server = {host = "*", port = 8080},
    
    defaultHost = {},
    
    virtualhosts = {
        ["www.sitename.com"] = simplerules
    }
}

Running

Running Xavante requires the execution of the correctly set xavante_start.lua. This can be done through a xavante.bat file in Windows, or by giving execution rights to the xavante_start.lua on Unix.

The example below is a xavante.bat that can be used to start Xavante on Windows using the same configuration as the above examples.

@c:\kepler\lua5.1.exe c:\kepler\xavante_start.lua

After Xavante is started, opening the URL http://localhost:8080 on your browser should show the Xavante welcome page. If you changed the port number on config.lua you should also use this port number in the URL.

The welcome page presents the Xavante version and links to the documentation and to a simple set of tests.

As a final note, if you start Xavante like this example showed, you will have to kill the process to stop Xavante since there is no "xavante_stop.lua". Kepler allows greater Xavante control in Windows by using a Xavante tray bar application that offers options to start and stop Xavante at will. For more detail consult the Kepler documentation.

Valid XHTML 1.0!

$Id: manual.html,v 1.44 2007/08/24 20:13:16 carregal Exp $