如何在 IIS 上搭建 mercurial server

简介: mercurial server 对于代码管理工具,更多的人可能更熟悉 Git 一些(Git 太火了)。其实另外一款分布式代码管理工具也被广泛的使用,它就是 mercurial。多人协作时,最好能够通过创建一个 mercurial server 对用户进行权限认证,同时也会方便持续集成。

mercurial server

对于代码管理工具,更多的人可能更熟悉 Git 一些(Git 太火了)。其实另外一款分布式代码管理工具也被广泛的使用,它就是 mercurial。多人协作时,最好能够通过创建一个 mercurial server 对用户进行权限认证,同时也会方便持续集成。

关于创建 mercurial server 的步骤,mercurial 官方的 wiki 有说明,网上也有很多朋友分享了自己的创建过程。但笔者在创建的过程中还是颇费了一番周折才最终成功,所以也在此分享一下自己的经验,希望对朋友们有所帮助。

一、环境及软件安装

笔者使用的操作系统为 Server2012R2 x64 Standard 中文版。

首先,在安装其他工具前,需要先安装 IIS。安装 IIS 时需要注意,一定要把 CGI 和 ISAPI 这两个选项都勾选上。

然后,安装 Python,使用默认设置安装 python 2.7.x。

最后,安装 mercurial server,请从这里在这里下载 mercurial server 的安装包并安装,安装完成后检查 C:\Python27\Lib\site-packages\mercurial 目录是否被正确安装!

注意,python 和 sercurial server 必须保持相同的架构,不要一个安装 x86 另一个安装 x64。

二、设置 IIS 服务器支持 python 模块

在 IIS 管理器中选择 IIS server,双击”ISAPI 和 CGI 限制”,添加一项新的扩展:

1

喜欢使用命令行的同学也可以通过一行命令直接搞定:

C:\Windows\system32\inetsrv\appcmd set config /section:isapiCgiRestriction /+"[path='C:\Python27\python.exe -u %22%s%22',description='Python',allowed='True']"

三、创建网站

在 IIS 中创建一个新的网站,端口绑定81(80端口已被默认网站占用)。在网站的根目录中添加 web.config 文件,web.config 文件的内容为:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="Python" path="*.cgi" verb="*" modules="CgiModule" scriptProcessor="C:\Python27\python.exe -u &quot;%s&quot;" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
  </system.webServer>
</configuration>

需要注意文件中 python.exe 的路径,请根据自己机器上的安装目录进行配置。

网站的基本设置已经完成,下面写个简单的测试文件检查一下网站能否正常工作。

在网站的根目录下创建 test.cgi 文件,文件内容如下:

print 'Status: 200 OK'
print 'Content-Type: text/html'
print
print '<html><body><h1>Hello world!</h1></body></html>'

在浏览器中访问 http://localhost:81/test.cgi,如果看不到”Hello world!”,请检查前面的步骤是否执行正确。

四、配置 mercurial server

1. 在网站的根目录下添加 hgweb.config 文件,内容如下:

[collections]
C:\repos = C:\repos

[web]
push_ssl = false
allow_push = *

2. 在网站的根目录下添加 hgweb.cgi 文件,内容如下:

#!/usr/bin/env python
# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = "xxxxx\hgweb.config"

from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb import hgweb, wsgicgi
application = hgweb(config)
wsgicgi.launch(application)

注意,请按实际情况配置 config 的路径。

这就 OK 了,让我们在 c:\repos 目录下初始化一个库然后访问 http://localhost:81/hgweb.cgi 看看:

2

五、配置 URL 重定向

每次都要在 URL 中输入 /hgweb.cgi,一来不方便,二来总感觉怪怪的。能不能输入 http://localhost:81 就可以正常访问呢?当然可以,只需添加一个重定向的配置就可以了。

首先,需要下载并安装IIS的插件:http://www.iis.net/downloads/microsoft/url-rewrite

然后,在 web.config 文件中添加 rewrite 元素,新的 web.config 文件内容为:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="Python" path="*.cgi" verb="*" modules="CgiModule" scriptProcessor="C:\Python27\python.exe -u &quot;%s&quot;" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
    <rewrite>
      <rules>
        <rule name="rewrite to hgwebdir" patternSyntax="Wildcard">
          <match url="*" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="hgweb.cgi/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

好了,现在访问下 http://localhost:81 试试,和访问 http://localhost:81/hgweb.cgi 是一样的。

六、设置匿名访问权限

默认情况下我们已经可以使用匿名权限从服务器克隆库并进行操作了,但是当你执行 hg push 命令时会收到一个 HTTP Error 502: Bad Gateway 的错误。出现这个错误,是因为匿名用户没有修改服务器上文件的权限,所以我们需要给匿名身份验证设置一个有修改文件权限的用户。

3

现在就可以正常执行 push 操作了。

总结,相比其他工具的一键式安装与配置,mercurial server 的安装和配置稍显复杂。我们这里只是配置了最简单的匿名访问,并不支持 ssl,不过这在局域网中基本也够用了。

 

相关阅读:

最全的Windows Azure学习教程汇总

Azure Blob Storage 基本用法 -- Azure Storage 之 Blob

Azure Queue Storage 基本用法 -- Azure Storage 之 Queue

Azure File Storage 基本用法 -- Azure Storage 之 File

Azure Table storage 基本用法 -- Azure Storage 之 Table

 

相关文章
|
2月前
25、IIS服务器搭建(win server 2003)
25、IIS服务器搭建(win server 2003)
19 0
|
1月前
|
存储 网络安全 数据安全/隐私保护
Windows Server 2019 IIS HTTPS证书部署流程详解
Windows Server 2019 IIS HTTPS证书部署流程详解
|
1月前
|
Kubernetes 网络安全 Windows
要在云效部署到阿里云服务器上的 Windows Server 上的 IIS
【2月更文挑战第18天】要在云效部署到阿里云服务器上的 Windows Server 上的 IIS
159 4
|
11月前
|
Windows
windows server 2008 r2 IIS服务403-禁止访问访问被拒绝
windows server 2008 r2 IIS服务403-禁止访问访问被拒绝
196 0
25、IIS服务器搭建(win server 2003)
25、IIS服务器搭建(win server 2003)
63 0
25、IIS服务器搭建(win server 2003)
|
网络安全 Windows
Windows Server IIS配置 怎么禁用不安全的SSL2.0和SSL3.0协议?
Windows Server IIS配置 怎么禁用不安全的SSL2.0和SSL3.0协议?
267 0
|
网络安全 Windows
Windows Server IIS配置 怎么禁用不安全的SSL2.0和SSL3.0协议?
Windows Server IIS配置 怎么禁用不安全的SSL2.0和SSL3.0协议?
449 0
|
网络协议 文件存储 数据安全/隐私保护
通过安装和配置AD域解决Windows Server 2016的IIS无法加载SMB文件卷文件的问题
通过客户反馈我们发现Windows Server 2016的IIS无法加载SMB文件卷的文件,显示的错误是:未能加载文件或程序集。经过我们不断研究和实验,发现在安装和配置好AD域之后,2016上IIS加载文件卷文件发生错误的问题可以得到解决。
4113 0
通过安装和配置AD域解决Windows Server 2016的IIS无法加载SMB文件卷文件的问题
|
PHP
iis 访问HTTP 错误 500.0 - Internal Server Error无法在<fastCGI>应用程序配置中找到<handler> scriptProcessor
iis 访问HTTP 错误 500.0 - Internal Server Error无法在应用程序配置中找到 scriptProcessor
11747 0
|
弹性计算 .NET 数据库
ASP.NET MVC4网站部署在阿里ECS云服务器(WIndows Server 2012+IIS8环境)
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq1010885678/article/details/41747613 首...
1340 0