Howto WSGI » History » Revision 2
« Previous |
Revision 2/11
(diff)
| Next »
stbuehler, 2010-03-27 16:25
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 will use a lua action for this (here for the simple case http://wsgi.example.com/ - if you have an example for http://www.example.com/wsgi/ feel free to include it here):
-- wsgi.lua function wsgi_rewrite(vr) vr.phys.pathinfo = vr.req.uri.path vr.req.uri.path = "" end actions = wsgi_rewrite
Here the example config for http://xcache.lighttpd.net/ (trac is running as wsgi application)
setup { module_load ( "mod_expire", "mod_fastcgi", "mod_vhost" ); } 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"); include_lua "/etc/lighttpd2/wsgi.lua"; 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
Updated by stbuehler over 14 years ago · 2 revisions