I wanted to play with Django recently, so I needed to enable python support in lighttpd. I found a few links about using the default lighttpd.conf file, but I have a custom (minimalist) lighttpd.conf file that I don’t want to pollute with unnecessary options. It turns out that enabling python support through mod_cgi is quite trivial:
1. Open lighttpd.conf
".py" to the
static-file.exclude-extensions variable to prevent people from viewing the raw python code:
static-file.exclude-extensions = ( ".py" )
"mod_cgi" to the
server.modules = ( "mod_cgi" )
4. Add the association between *.py files and the python interpreter to the
cgi.assign = ( ".py" => "/usr/bin/python" )
5. Make sure you have a “breakage” log defined… this helps debugging because python errors will get written here:
server.breakagelog = "/var/log/lighttpd/breakage.log"
6. Restart lighttpd
For more mod_cgi configuration options, read this.