Setting up mercurial with HTTP authentication - Windows

This page describes a complete set of steps for installing hg as a windows service, along with nginx for HTTP proxy authentication. As it is, it is most appropriate for intranet configurations but by adding HTTPS to the mixture, the world is your sea food...

Wish list:

1. Download necessary files

2. Configuration

    <startargument>-p c:\nginx</startargument>
    <stopargument>-p c:\nginx -s stop</stopargument>

    server {
        listen       5000;
        server_name  mis-srv;
        access_log  logs/mis-srv.access.log;
        error_log  logs/mis-srv.error.log;
        location / {
            auth_basic           "Mercurial restricted";
            auth_basic_user_file passwd;
            proxy_pass           http://localhost:5500;


    <startargument>/c "c:\nginx\hg\hg-run start"</startargument>
    <stopargument>/c "c:\nginx\hg\hg-run stop"</stopargument>

Because winsw has a limitation where a single executable is assumed to start and stop the service, we need to use an intermediate .bat file to simulate this behaviour. Also note that we bind hg.exe to localhost only, so port 5500 will not be directly accessible outside our server.

    @echo off
    if "%1"=="start" (goto :start)
    taskkill /F /IM hg.exe /T
    goto :end
    "c:\Program Files\Mercurial\hg.exe" serve --address localhost --port 5500 --web-conf c:\nginx\hg\hgweb.conf

push_ssl = false
allow_push = *

test = c:\nginx\hg\repository\test

c:\nginx> nginx-service install
c:\nginx> hg-service install

And that's all!

3. Troubleshooting

If you have failed in starting services, check following items.

  1. hg-service.*, nginx-service.* and serviceslogs\ (create it) should be in c:\nginx\

  2. hg-run.bat, hgweb.conf and servicelogs\ (create it) should be in c:\nginx\hg\

  3. nginx.conf should be in c:\nginx\conf\. You don't need to create it. Just edit the existing file.

  1. Actually, it's not true. Create and copy .htpasswd from *nix machine, or use Htpasswd Generator for Windows, or use htpasswd.exe from Apache HTTP Server installation. (1)

HgServeNginxWindows (last edited 2011-10-06 12:17:05 by 212)