Book Image

Lighttpd

By : Andre Bogus
Book Image

Lighttpd

By: Andre Bogus

Overview of this book

Table of Contents (20 chapters)
Lighttpd
Credits
About the Author
About the Reviewer
Preface
HTTP Status Codes

Running mod_magnet


Having Lua embedded in the server means there is no redirection, no interprocess communication, and nothing to keep us from killing our Lighttpd if our code hangs. For this section, we should have installed mod_magnet in Chapter 1 (if not, go back there and reinstall). Now add the following to the configuration:

server.modules = ( #...
"mod_magnet", #...
)
# either of the following two:
magnet.attract-raw-url-to = ( "/path/to/my.lua" )
magnet.attract-physical-path-to = ( "/path/to/other.lua" )

The first option will invoke the magnet before Lighttpd has even inferred the physical path. We are operating directly on URLs. This is a good option if we want to code complex rewrite logic in Lua. The other option will hand the parsed request to our Lua script, which is fine when we want to manipulate the response.

mod_magnet gives us some hints at the request and environment, and some means to manipulate the request and the response. When our magnet script starts, the following...