Python – Configure FastCGI for Python

fastcgipythontrac

I have nginx running on a VM and I want to run a Trac site. I need to run a python FastCGI server, but I cannot tell which is the server to use. I have found the following:

  • Lighttpd spawn-fcgi But this seems to require that you compile lighttpd just to get the fcgi server, which is weird.
  • fcgi.py But this one seems to be deprecated. At the very least it is poorly documented.
  • flup This one comes with dependencies on ubuntu (python-cheetah{a} python-mysqldb{a} python-webpy{a}) that seem unnecessary. Also poorly documented.

Are there any recent guides for setting this up? Trac's own FastCGI setup page seems to miss some steps.

Best Answer

trac should be now WSGI compliant, so you can use any supported method to run the site. If it is a low traffic site, you can always use CGI, and eventually move to something else later if you need it. For the other methods, use mod_wsgi or install flup for FCGI (even if it installed extra dependencies).

To use flup, you have to import the appropriate WSGI server, then run it, i.e.

from flup.server.fcgi_fork import WSGIServer
def main_app(...):
  ...

WSGIServer(main_app).run()

If you want to run it as external server (i.e. not started by the web server), substitute this:

WSGIServer(main_app,bindAddress=('1.2.3.4',9999)).run()