Howto WSGI¶
WSGI is not an application and not a communication "method" itself (like FastCGI, SCGI or "CGI"); it is a protocol, what informations the webserver should send to an web application (so it it basically is an CGI extension for applications instead of simple scripts), see http://wsgi.org/wsgi/What_is_WSGI.
Most python web applications use WSGI, and the wsgi handlers for python provides support for running the application as a simple webserver, FastCGI or SCGI application.
Our recommended way to run WSGI web applications is with FastCGI, and that is what is described here.
Lighttpd config¶
WSGI wants the url to be splitted in the "application path" (SCRIPT_NAME) and the remaining part (PATH_INFO) - so the webserver detects the application path, and tells the application to handle the remaining part. This allows you to host the same WSGI application on different hostnames and paths, for example you could host it on http://wsgi.example.com/ and http://www.example.com/wsgi/, without the need of configuring your WSGI application for it.
So you somehow have to split the url into the required parts, and we use a lua action for this.
You can find the source code for it in our repository, source:contrib/core.lua (documentation with examples in the source); see mod_core.
Here the example config for http://xcache.lighttpd.net/ (trac is running as wsgi application)
setup { module_load ( "mod_expire", "mod_fastcgi", "mod_vhost", "mod_lua" ); lua.plugin "core.lua"; } var.vhosts = []; # ... var.vhosts = var.vhosts + [ "xcache.lighttpd.net" => { docroot "/var/www/servers/xcache.lighttpd.net"; alias ( "/trac-static/" => "/usr/share/trac/htdocs", "/chrome/common/" => "/usr/share/trac/htdocs" ); if request.path =~ "\.(css|png|js|gif)$" { expire "access 1 week"; } if physical.is_file { header.add ("X-cleanurl", "hit"); } else { header.add ("X-cleanurl", "miss"); core.wsgi ( "", { fastcgi "unix:/var/run/lighttpd/sockets/xcache.lighttpd.net.sock"; } ); } } ]; # ... vhost.map var.vhosts;
Spawning your wsgi application¶
Have a look at Howto_Rails to see how spawning in general can work. For trac the final spawn-fcgi line may look something like this:
exec /usr/bin/spawn-fcgi -n -u www-trac -U www-data -s /var/run/lighttpd/sockets/xcache.lighttpd.net.sock -- /usr/share/trac/web/fcgi_frontend.py
HowTo Python WSGI for lighttpd 1.4.x¶
https://redmine.lighttpd.net/projects/lighttpd/wiki/HowToPythonWSGI
Updated by gstrauss about 8 years ago · 11 revisions