Web Hosting on Microsoft IIS

Ezra.Smith at bentley.com Ezra.Smith at bentley.com
Tue Oct 23 15:34:11 CDT 2007


For anyone interested in hosting Mercurial repositories on a Microsoft
IIS server:

We've been trying to set one up here on IIS 5.1. I haven't seen any
mention of other users running hg repositories on IIS, so here are some
tips for those who may want to...

(1)  You'll need to patch hgwebdir_mod.py (or hgweb_mod.py, though I
haven't tried using that). IIS doesn't have a 'REQUEST_URI' environment
variable, so the following patch defines it in hgwebdir_mod.py if you're
using IIS:

diff -Naur a\mercurial\hgweb\hgwebdir_mod.py
b\mercurial\hgweb\hgwebdir_mod.py
--- a\mercurial\hgweb\hgwebdir_mod.py   Tue Oct 23 15:50:58 2007
+++ b\mercurial\hgweb\hgwebdir_mod.py   Tue Oct 23 15:51:03 2007
@@ -88,6 +88,11 @@
         def config(section, name, default=None, untrusted=True):
             return parentui.config(section, name, default, untrusted)

+        if (req.env['SERVER_SOFTWARE'].split('/')[0] ==
'Microsoft-IIS'):
+            iis_scriptname = req.env['SCRIPT_NAME']
+            iis_pathinfo = req.env['PATH_INFO']
+            req.env['REQUEST_URI'] = req.env['PATH_INFO'] =
iis_pathinfo[len(iis_scriptname):]
+
         url = req.env['REQUEST_URI'].split('?')[0]
         if not url.endswith('/'):
             url += '/'

(2) Using a rewrite mod for IIS is helpful. We're using ISAPI_Rewrite
Lite (it's free, though not open source) to remap our URLs and hide the
"hgwebdir.cgi" part (much like Apache/lighttpd do, as outlined in the hg
book).

(3) When users go to www.server.com/hgwebdir.cgi/some/address, the
hgwebdir.cgi script needs to be invoked. For that to happen, when you
use the "Add/Edit Application Extension Mapping" dialog to map .cgi
extensions to Python, you want to make sure that "Check that file
exists" is unchecked. Otherwise, the server will make sure that
/hgwebdir.cgi/some/address exists before passing control to your script,
and...well, it's a virtual address, it doesn't exist, and the cgi script
won't be called.

(4)  By default, IIS has a built-in 5 minute timeout on scripts that
it's running. You'll want to increase this, because otherwise
cloning/pulling will keep failing with seemingly random errors on a
large repository. The timeout appears to reset if the client/server
exchange new HTTP requests/responses, but the stream of TCP data that
happens between those HTTP requests won't affect the timeout. I'm not
actually sure what a good timeout value is, though, and suggestions
would be appreciated there. We'd like a developer on the other side of
the world to be able to do a full clone without a timeout occurring (our
repository is ~40k changesets and 1.3 GB), but it'd also be nice not to
let scripts run indefinitely.

On IIS 5.1, changing the timeout is a little counter-intuitive. There's
a CGI timeout setting under the root "Web Sites" folder, but it doesn't
actually affect the mercurial repo. Instead, you want to go to the
repository web site's properties (one level below the Web Sites root).
Under the "Home Directory" tab, set "Application Protection" to "High
(Isolated)". Then click the "Configuration" button, and a Process
Options tab will have appeared (it doesn't show in Low or Medium
protection modes). Change the CGI script timeout there.

I've read that on IIS 6, this no longer works, and you actually have to
download a resource toolkit to adjust the timeout value. I haven't
confirmed that yet.

-Ezra


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://selenic.com/pipermail/mercurial/attachments/20071023/449450a9/attachment.htm 


More information about the Mercurial mailing list