配置HG服务器

来源:互联网 发布:免费的网上审批软件 编辑:程序博客网 时间:2024/05/17 05:10

Mercurial + Nginx + Windows 构建代码管理


我的目的是建立一个基于http的 mercurial服务器,而且支持用户认证的访问,mercurial本来是自带一个轻量级的http服务的,但是出于安全
我用Nginx的反向代理功能提供Mercurial的对外访问。

1. 下载
http://tortoisehg.bitbucket.org/
http://mercurial.selenic.com/
http://nginx.org/en/download.html

2. 安装
Mercurial需要安装,Nginx不需要,随便找个目录解压缩就好了。

3. 建立Mercurial的代码仓库
随便建个目录,比如 c:\mercurial\repos
hg init

4. 配置mercurial 并启动 mercurial 的http服务
hg serve -d -a localhost -p 8000 --webdir-conf hgweb.config
-d 是指后台运行
-a 指定 localhost是为了限制mercurial只能从本机访问
--webdir-conf 指定 mercurial的 web配置文件为 hgweb.config

hgweb.config的内容很简单
[web]
push_ssl = false
allow_push = *
[paths]
/myhg = c:\mercurial\repos\

允许push的时候不需要 https ,允许所有人push,把mercurial的代码库映射到web上的 /myhg 目录

5. 修改nginx的配置
到nginx/conf 目录下打开 nginx.conf,修改成如下的样子。
        location / {
            root   html;
            index  index.html index.htm;
            auth_basic           "Restricted";
            auth_basic_user_file htpasswd;
            proxy_pass           http://localhost:8000;
        }
使用简单的密码校验,反向代理到 localhost:8000

6. 配置用户和密码
在 nginx的 conf下,建立一个叫  htpasswd 的文件,纯文本,每一行是一对 用户名密码,冒号分隔,比如:
tom:1234
mike:5678

7. 最后启动nginx
直接运行 nginx.exe就好了,用浏览器打开 你的主页看看吧

原创粉丝点击