最近,我意外地发现,Mercurial存储库所在的BitBucket不再支持Mercurial:不再可以创建新存储库,现有存储库将从1.06.2020中删除。可能的选项:转到Git,选择其他服务之一,或在服务器上设置Mercurial托管。我有一台服务器,我不想放弃Mercurial并改变我的习惯,我也不喜欢BitBucket的替代方案,所以我选择了最后一个选项。任务似乎很简单,只有服务器在Windows下,并且在设置过程中,我设法迈出了最大的步伐。希望本文能帮助某人避免这种情况并节省一些时间。
文档中介绍了用于组织Mercurial托管的各种选项。他们可以分为3组:
- 汞服务 -即 Mercurial本身以服务器模式启动。
- HgWeb.cgi是Mercurial发行版中包含的官方脚本。
- 外部开发人员提供的解决方案功能更强大,但有其局限性,而且通常需要付费。
HG服务
最简单,最合乎逻辑的是第一个选项。根据文档,Mercurial具有运行HgWeb的内置Web服务器-这是运行hg serve时起作用的方法。该服务器不知道如何进行身份验证,即不能请求用户登录名/密码,但可以进行授权,即根据访问设置,授予/不授予这种或那种类型的存储库访问权限。如果我们需要私有存储库,那么为了进行身份验证,可以将Nginx用作将请求密码的代理服务器。这里描述了建立这样的电路。
为了方便起见,hg serve以使用winsw的服务形式启动,该实用程序允许您以服务的形式运行任何命令(在这种情况下,通常是bat文件)。但是,启动时可以不使用服务,例如,在任务计划程序中使用触发器“在系统启动时”创建任务-这样的任务将在系统启动时启动。但这是一个不太可靠的选择:万一发生故障,该任务将不会重新启动,并且日志中将没有关于此的信息。
请注意配置文件(hgweb.conf / hgrc):
- 它们的内容区分大小写:例如,如果您
[Web]
改为编写[web]
,则它将不起作用。 - 等号必须用空格包围:如果您编写
push_ssl=false
,它将无法正常工作,您需要编写push_ssl = false
。
, Mercurial push , "Hello world", . Nginx :
client_max_body_size 500M;
proxy_read_timeout 120s;
, , .
hgweb.conf . ( ), : /.hg/hgrc , , , .
, Mercurial , Nginx. : Mercurial , Nginx . Nginx :
proxy_set_header REMOTE_USER $remote_user;
:
proxy_set_header X-Forwarded-User $remote_user;
:( HgWeb, ENV('REMOTE_USER'), — .
, Nginx 2 ( ) hg serve, hgweb.conf
. , hgweb.conf
( ) . , . .
HgWeb.cgi
, Python- HgWeb. Mercurial , . , (CGI) , — WSGI FCGI.
Nginx CGI, WSGI WSGI- ( Windows ), FCGI — FastCGI. Python, , Python , Mercurial — 2.7. , 2.7. HgWeb Python Flup, , ( Python 2.7). :
pip install flup==1.0.3.dev-20110405
hgweb.fcgi — ( ) , ( ):
WSGIServer(application, bindAddress=("127.0.0.1",5500)).run()
Nginx:
location / {
auth_basic "My Repos";
auth_basic_user_file passwd;
include fastcgi.conf;
fastcgi_split_path_info ^()(.*)$;
fastcgi_param SCRIPT_NAME "";
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param AUTH_USER $remote_user;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_pass 127.0.0.1:5500;
}
location /static/ {
root e:/Mercurial/templates;
}
fastcgi.conf
, fastcgi location
. PATH_INFO
— . url , PATH_INFO.
:
python hgweb.fcgi
!
hg serve, HgWeb . winsw. bat-:
@echo off
if "%1"=="start" (goto :start)
:stop
taskkill /F /IM python-hg.exe /T
goto :end
:start
"c:\Python27\python-hg.exe" e:\Mercurial-5.3\hgweb.fcgi
:end
, python.exe
python-hg.exe
taskkill
.
: "Local System" — ! , .
, HgWeb ( hg serve) . : , , Nginx location
. :
location /Base/ {
include fastcgi.conf;
fastcgi_split_path_info ^()(.*)$;
fastcgi_param SCRIPT_NAME "";
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param AUTH_USER "pub";
fastcgi_param REMOTE_USER "pub";
fastcgi_pass 127.0.0.1:5500;
}
— Base
.
, . ( , Python , , :-)