[nginx] Running Mercurial using Nginx as http server

Thomas iamkenzo at gmail.com
Sat Jan 26 20:27:10 MSK 2008


I am having some troubles getting Mercurial (the distributed Version
Control System) to work with nginx. It uses a cgi script (hgweb.cgi)
to launch mercurial which is a python program.

I have set up the cgi support in nginx using this documentation page:

This setup with simple scripts works fine.

Now if I want to move to using Mercurial, when I call the cgi script
that triggers mercurial, I get the following Python error in my web
By the way seeing this error message means that the cgi script is
being processed, so cgi does work. It's the cgi->python that goes
A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.
 /var/hg/hgweb.cgi in ()
   34 from mercurial.hgweb.hgweb_mod import hgweb
   35 import mercurial.hgweb.wsgicgi as wsgicgi
   37 application = hgweb("/var/hg/repo1", "repository name")
   38 wsgicgi.launch(application)
wsgicgi = <proxied module 'wsgicgi'>, wsgicgi.launch = <function
launch at 0xb7c8f304>, application = <mercurial.hgweb.hgweb_mod.hgweb
object at 0xb7db050c>
 /var/lib/python-support/python2.5/mercurial/hgweb/wsgicgi.py in
launch(application=<mercurial.hgweb.hgweb_mod.hgweb object at
   62         return write
   64     result = application(environ, start_response)
   65     try:
   66         for data in result:
result undefined, application = <mercurial.hgweb.hgweb_mod.hgweb
object at 0xb7db050c>, environ = {'CONTENT_LENGTH': '',
'CONTENT_TYPE': '', 'DOCUMENT8ROOT': '/usr/local/nginx/html',
'DOCUMENT_ROOT': '/var/hg', 'DOCUMENT_URI': '/hgweb.cgi', 'FCGI_ROLE':
'ignoreboth', 'HOME': '/home/thomas', 'HTTP_ACCEPT':
...}, start_response = <function start_response at 0xb7c8f41c>

<type 'exceptions.TypeError'>: 'hgweb' object is not callable
      args = ("'hgweb' object is not callable",)
      message = "'hgweb' object is not callable"

I don't know Pyhton, but it seems that hgweb which is a module is not
imported thus not callable.

In the Mercurial documentation page, it says: "Remember that the web
server runs the CGI program without any of the environment variables
that you take for granted in an interactive sessions."

So how can I tell Python where to look the modules for? This should be
set in the cgi script I guess, but how to specify it?

I tried inside hgweb.cgi:

import sys
sys.path.insert(0, "/usr/lib/python2.5")
sys.path.insert(0, "/usr/lib/python-support")
sys.path.insert(0, "/usr/local/lib/python2.5")
sys.path.insert(0, "/var/lib/python-support/python2.5/mercurial/hgweb")
sys.path.insert(0, "/usr/share/python-support/mercurial/mercurial/hgweb")

import os
os.environ["PYTHONPATH"] = "/usr/lib/python2.5"
os.environ["PYTHONPATH"] = "/usr/lib/python-support"
os.environ["PYTHONPATH"] = "/usr/local/lib/python2.5"

But I still get the exact same error message. Are there some Python
programmers that could help me out? I am using Ubuntu 7.10 server

More information about the nginx mailing list