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
2. Add ".py" to the static-file.exclude-extensions variable to prevent people from viewing the raw python code:
static-file.exclude-extensions = ( ".py" )
3. Add "mod_cgi" to the server.modules variable:
server.modules = ( "mod_cgi" )
4. Add the association between *.py files and the python interpreter to the cgi.assign variable:
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.


Thanks for this, how did you get Django running with mod_cgi? I’ve been looking around, but have been unable to find instructions on getting Django running with Lighttpd + mod_cgi.
Reply