Differences between revisions 8 and 9
Revision 8 as of 2013-11-19 22:28:46
Size: 1932
Comment: Specify nginx reverse proxy setup.
Revision 9 as of 2014-01-03 15:20:11
Size: 1971
Comment: Consolidating nginx-specific configuration (hg serve and hgweb)
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from HgServeNginx

{i} This page does not meet our wiki style guidelines. Please help improve this page by cleaning up its formatting.

Note:

This page appears to contain material that is no longer relevant. Please help improve this page by updating its content.

Configure Nginx (reverse proxy)

This is a solution I found for hosting personal projects. I was already using Nginx, didn't want to mess with (Fast)CGI, but still wanted some basic authentication for pushing. This method allows repositories to be served using hg serve, and then be cloned and accessed via the web interface anonymously, but HTTP authentication is required for pushing.

This method relies on a running "hg serve" instance. The web server is only a reverse proxy, transactions as submitted to running mercurial instance.

The first step is to configure Nginx.

server {
    listen      80;
    server_name <your-server-name>;    # standard stuff
    access_log  /path/to/access/log;
    error_log   /path/to/error/log;

    location / {
        limit_except GET { # do this for all requests but GETS
            auth_basic           "Restricted";
            auth_basic_user_file /path/to/htpasswd/file;
            proxy_pass http://localhost:8000;
        }

    proxy_pass http://localhost:8000; # or wherever hg serve is running
    }
}

1. Configure htpasswd

cd into the root directory of your repos (i.e. /var/hg/repos), and run htpasswd -c <file-name> <user-name> and supply a password. If you want to give a new user commit rights, simply cd back to that directory and run htpasswd <file-name> <user-name>.

2. Configure hg

The final step is to configure your repository's hgrc file, located at <repo-name>/.hg/hgrc. The import things in hgrc are to make sure that, in the [web] section, push_ssl is set to false and allow_push is set to *.

3. Serve

Now run hg serve as normal, and you should be able to access the web interface and clone the repository with no authentication, but to push to the central repository you need to have a user name and password from the htpasswd file.

PublishRepositoriesOnNginx (last edited 2018-06-09 07:35:07 by AntonShestakov)