windows 如何在 IIS 上设置 Mercurial 和 hgwebdir?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/818571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:19:20  来源:igfitidea点击:

How do I set up Mercurial and hgwebdir on IIS?

windowsiismercurial

提问by Kevin Berridge

I've been looking all over for decent instructions on how to get hgwebdir working on IIS but I haven't found much of worth.

我一直在寻找有关如何让 hgwebdir 在 IIS 上工作的体面说明,但我没有发现太多价值。

There's this "step by step"on the Mercurial wiki, but it's not very good. There's also thisand this, but again, I can't find good steps to lead up to where those get started.

Mercurial wiki 上有这个“循序渐进”,但不是很好。还有thisthis,但同样,我找不到好的步骤来引导那些开始的地方。

回答by jwanagel

I just had to install a fresh Mercurial instance yesterday, here's updated instructions for 1.7:

我昨天只需要安装一个新的 Mercurial 实例,这里是 1.7 的更新说明:

  1. Install Mercurial(these instructions were tested with 1.7)
  2. Install Python(for Mercurial 1.7, you must use the x86 version of Python 2.6.6)
  3. You will need to download the hgweb.cgi file from the Mercurial source. You can download the source by running: hg clone https://www.mercurial-scm.org/repo/hg/
  4. Create a folder that will be your web application folder. You will need to copy three things into this folder:

    • The hgweb.cgi file
    • The contents of the Library.zip from your "C:\Program Files\Mercurial" folder
    • The Templates folder from your "C:\Program Files\Mercurial"
  5. You will need to make sure you have Python set up in IIS.

    • Enable CGI via the following: Control Panel -> Turn Windows Features On or Off -> Roles -> Web Server (IIS) -> Add Role Services -> Check CGI
    • Create a new Web Site in IIS and make sure the physical path is the folder you created above
    • In the Handler Mappings for the new website, select "Add Script Map". Enter *.cgifor the request path, c:\Python26\python.exe -u "%s"for the Executable, and Pythonfor the Name.
  6. You will also need to create a file named "hgweb.config" with contents similar to below. The path within the file needs to be the location on your drive where you want to store the Mercurial repositories:

    [collections]
    c:\Mercurial\repos = c:\Mercurial\repos

  7. Edit the hgweb.cgi file and change the line where it sets the path to your hgweb.config to something like the following (wherever the hgweb.config file is):

    config = "C:\Mercurial\hgweb.config"

  8. Now, open a browser and navigate to http://localhost/mercurial/hgweb.cgi(or whatever is the appropriate URL path you set up in IIS) and you should see the Mercurial Repositories page.
  1. 安装 Mercurial(这些说明在 1.7 中测试过)
  2. 安装 Python(对于 Mercurial 1.7,必须使用 Python 2.6.6 的 x86 版本)
  3. 您需要从 Mercurial 源下载 hgweb.cgi 文件。您可以通过运行以下命令下载源代码:hg clone https://www.mercurial-scm.org/repo/hg/
  4. 创建一个文件夹,作为您的 Web 应用程序文件夹。您需要将三件事复制到此文件夹中:

    • hgweb.cgi 文件
    • “C:\Program Files\Mercurial”文件夹中 Library.zip 的内容
    • “C:\Program Files\Mercurial”中的 Templates 文件夹
  5. 您需要确保在 IIS 中设置了 Python。

    • 通过以下方式启用 CGI:控制面板 -> 打开或关闭 Windows 功能 -> 角色 -> Web 服务器 (IIS) -> 添加角色服务 -> 检查 CGI
    • 在IIS中新建一个网站,并确保物理路径是你上面创建的文件夹
    • 在新网站的处理程序映射中,选择“添加脚本映射”。为请求路径输入*.cgi,为可执行文件输入c:\Python26\python.exe -u "%s",为名称输入Python
  6. 您还需要创建一个名为“hgweb.config”的文件,其内容类似于以下内容。文件中的路径必须是您要存储 Mercurial 存储库的驱动器位置:

    [收藏]
    c:\Mercurial\repos = c:\Mercurial\repos

  7. 编辑 hgweb.cgi 文件并将其设置 hgweb.config 路径的行更改为如下所示(无论 hgweb.config 文件在哪里):

    config = "C:\Mercurial\hgweb.config"

  8. 现在,打开浏览器并导航到http://localhost/mercurial/hgweb.cgi(或您在 IIS 中设置的任何适当的 URL 路径),您应该会看到 Mercurial Repositories 页面。

Also, check out Jeremy Skinners blog post. It's a little outdated, but has some extra nice steps like setting up URL re-writing for cleaner URL's.

另外,请查看Jeremy Skinners 博客文章。它有点过时,但有一些额外的好步骤,例如为更干净的 URL 设置 URL 重写。

回答by Ken Pespisa

It seems since Mercurial 1.5.2 was released, these tutorials don't work exactly right. For one thing, hgwebdir.cgi has been removed, and is now replaced with hgweb.cgi.

似乎自从 Mercurial 1.5.2 发布以来,这些教程并不完全正确。一方面,hgwebdir.cgi 已被删除,现在替换为 hgweb.cgi。

The instructions that worked best for me is at eworldui.net:

最适合我的说明在eworldui.net 上

http://www.eworldui.net/blog/post/2010/04/08/Setting-up-Mercurial-server-in-IIS7-using-a-ISAPI-module.aspx

http://www.eworldui.net/blog/post/2010/04/08/Setting-up-Mercurial-server-in-IIS7-using-a-ISAPI-module.aspx

Those instructions are meant for IIS 7 or greater. If you're setting this up on IIS 6, I wrote up similar instructions geared toward Win2k3 and IIS 6.0:

这些说明适用于 IIS 7 或更高版本。如果您在 IIS 6 上进行设置,我编写了针对 Win2k3 和 IIS 6.0 的类似说明:

http://partialclass.blogspot.com/2010/05/setting-up-mercurial-server-on-win2k3.html

http://partialclass.blogspot.com/2010/05/setting-up-mercurial-server-on-win2k3.html

UPDATE:Shortly after getting this working I learned that BitBucket changed their pricing scheme to offer free, unlimited, private hosting: https://bitbucket.org/. I would've opted for that in a heartbeat when I was originally working on this project.

更新:在完成这项工作后不久,我了解到 BitBucket 更改了他们的定价方案,以提供免费、无限制的私人托管:https: //bitbucket.org/。当我最初从事这个项目时,我会立即选择它。

回答by BenAlabaster

I found that the blog post at Vampire Basicwas a good start, but it didn't go into nearly enough detail for what I was after.

我发现Vampire Basic上的博客文章是一个好的开始,但它没有详细说明我所追求的内容。

I did a 4 part blog post on this that gets you up and running from scratch with IIS, including Active Directory integration, setting up of security privileges for push/pull, customization of the template, I'd reproduce it here, but it's quite long winded being that Mercurial was really designed to be hosted on Linux/Apache:

我写了一篇关于此的 4 部分博客文章,让您从头开始使用 IIS,包括 Active Directory 集成、设置推/拉安全权限、自定义模板,我会在此处复制它,但它相当啰嗦的是,Mercurial 真正设计为托管在 Linux/Apache 上:

http://www.endswithsaurus.com/2010/05/setting-up-and-configuring-mercurial-in.html

http://www.endswithsaurus.com/2010/05/setting-up-and-configuring-mercurial-in.html

回答by Ben Schwehn

There's a fairly good and comprehensive tutorial here: http://vampirebasic.blogspot.com/2009/06/running-mercurial-on-windows.html

这里有一个相当不错和全面的教程:http: //vampirebasic.blogspot.com/2009/06/running-mercurial-on-windows.html

回答by Clay Lenhart

Below are what I did after doing a fair amount of research for geting hgwebdir.cgi setup on IIS6 . It is based on the following sites:

以下是我在为在 IIS6 上设置 hgwebdir.cgi 进行了大量研究后所做的工作。它基于以下站点:

You'll need to install the following on the server:

您需要在服务器上安装以下内容:

  • Mercurial (I used version 1.5)
  • Python 2.6. The version of Python depends on the version of Mercurial installed. Mercurial 1.5 uses Python 2.6. Install x86 even if you are running x64.
  • Mercurial(我使用的是 1.5 版)
  • 蟒蛇 2.6。Python 的版本取决于安装的 Mercurial 版本。Mercurial 1.5 使用 Python 2.6。即使您运行的是 x64,也要安装 x86。

The steps for me were:

我的步骤是:

  • Create a directory for the website. I used c:\inetpub\wwwroot\hg.
  • In IIS, right click on the folder for hg, select properties, select the Home Directory tab.
  • Click on the Create application button. Set the execute permissions to "scripts".
  • Still in the Home Directory tab, click on the Configuration button. In the "Application Configuration" popup, click the Add button to add an application extension. The Executable is c:\Python26\python.exe -u "%s" "%s". The extension is .cgi. Set the "verbs" to "limit to: GET,HEAD,POST". Check both Script engine and Verify that file exists.
  • In the Directory Security tab, click on the Edit button in the Authentication and access control section. Uncheck all authentication methods, and check the "Basic authenication" method. Set the Default domain if you like to your Active Directory domain.
  • In IIS, click on the Web Service Extensions folder on the left panel. Click on "Add a new Web service extension" link. Extension name should be Python, the required file is c:\Python26\python.exe -u "%s" "%s". Make sure the new extension is "Allowed".
  • 为网站创建一个目录。我使用了 c:\inetpub\wwwroot\hg。
  • 在 IIS 中,右键单击 hg 的文件夹,选择属性,选择主目录选项卡。
  • 单击创建应用程序按钮。将执行权限设置为“脚本”。
  • 仍然在主目录选项卡中,单击配置按钮。在“应用程序配置”弹出窗口中,单击“添加”按钮以添加应用程序扩展。可执行文件是 c:\Python26\python.exe -u "%s" "%s"。扩展名为 .cgi。将“动词”设置为“限制为:GET、HEAD、POST”。检查脚本引擎并验证文件是否存在。
  • 在目录安全选项卡中,单击身份验证和访问控制部分中的编辑按钮。取消选中所有身份验证方法,然后选中“基本身份验证”方法。如果您喜欢 Active Directory 域,请设置默认域。
  • 在 IIS 中,单击左侧面板上的 Web Service Extensions 文件夹。单击“添加新的 Web 服务扩展”链接。扩展名应该是 Python,需要的文件是 c:\Python26\python.exe -u "%s" "%s"。确保新扩展名是“允许的”。

Now is a good time to test that Python is working. Create a file in your new Hg folder called test.cgi. Paste the following python code:

现在是测试 Python 是否正常工作的好时机。在新的 Hg 文件夹中创建一个名为 test.cgi 的文件。粘贴以下python代码:

print 'Status: 200 OK'
print 'Content-type: text/html'
print

print '<html><head>'
print ''
print '<h1>It works!</h1>'
print ''
print ''

Open the browser to your site, for instance, http://localhost/hg/test.cgi

打开浏览器访问您的站点,例如http://localhost/hg/te​​st.cgi

You should see "It works!" in the browser.

您应该会看到“它有效!” 在浏览器中。

Next let's get the hgwebdir working.

接下来让我们让 hgwebdir 工作。

  • Delete test.cgi
  • clone the hg repo to a new directory: https://www.mercurial-scm.org/repo/hg/
  • copy hgwebdir.cgi to your web directory: c:\inetpub\wwwroot\hg\ from the cloned hg repo
  • Edit the file and change
  • 删除test.cgi
  • 将 hg repo 克隆到一个新目录: https://www.mercurial-scm.org/repo/hg/
  • 将 hgwebdir.cgi 复制到您的 Web 目录:c:\inetpub\wwwroot\hg\ 从克隆的 hg 存储库
  • 编辑文件并更改
application = hgwebdir('hgweb.config')
wsgicgi.launch(application)
application = hgwebdir('hgweb.config')
wsgicgi.launch(application)

to

application = hgwebdir('c:\inetpub\wwwroot\hg\hgweb.config')
wsgicgi.launch(application)
application = hgwebdir('c:\inetpub\wwwroot\hg\hgweb.config')
wsgicgi.launch(application)
  • Unzip the Library.zip file in the Mercurial directory, c:\Program Files\Mercurial\, to your web directory, c:\inetpub\wwwroot\hg\
  • Copy the templates directory from c:\Program Files\Mercurial\templates\ to c:\inetpub\wwwroot\hg\templates\
  • Create a file called hgweb.config in your web directory.
  • 将 Mercurial 目录 c:\Program Files\Mercurial\ 中的 Library.zip 文件解压到您的 Web 目录 c:\inetpub\wwwroot\hg\
  • 将模板目录从 c:\Program Files\Mercurial\templates\ 复制到 c:\inetpub\wwwroot\hg\templates\
  • 在您的 Web 目录中创建一个名为 hgweb.config 的文件。

Now is a good time to test it out. Go to the following URL in the browser, http://localhost/hg/hgwebdir.cgi

现在是测试它的好时机。在浏览器中访问以下 URL,http://localhost/hg/hgwebdir.cgi

  • Edit hgweb.config, and paste the following:
  • 编辑 hgweb.config,并粘贴以下内容:
[collections]
\server\share$\Hg\ = \server\share$\Hg\
[web]
allow_push = *
push_ssl = false
[collections]
\server\share$\Hg\ = \server\share$\Hg\
[web]
allow_push = *
push_ssl = false

These are all my preferences, for instance we have our repos in subdirectories at \\server\share$\Hg. The web app will run under the permissions of the logged in user via the browser, so they'll need read/write permissions to the share.

这些都是我的偏好,例如我们在 \\server\share$\Hg 的子目录中有我们的存储库。Web 应用程序将通过浏览器在登录用户的权限下运行,因此他们需要对共享的读/写权限。

The last step is to allow for long connections which can happen when you first clone a repo. Run the following command to increase the timeout to 50 minutes:

最后一步是允许长连接,这在您第一次克隆存储库时可能发生。运行以下命令将超时增加到 50 分钟:

cd \inetpub\AdminScripts\
cscript adsutil.vbs GET /W3SVC/CGITimeout 
cscript adsutil.vbs SET /W3SVC/CGITimeout 3000

回答by Aaron Watters

Use mercurial to clone the mercurial repository:

使用 mercurial 克隆 mercurial 仓库:

hg clone https://www.mercurial-scm.org/repo/hg/

you will find hgwebdir.cgi at the top level. It should install like any other cgi script.

您会在顶层找到 hgwebdir.cgi。它应该像任何其他 cgi 脚本一样安装。

回答by Brook

I've been fighting with this setup for mercurial 1.7.2 for the past week or so, I had to do things slightly differently than the above articles do in order to get it working.

在过去一周左右的时间里,我一直在与 mercurial 1.7.2 的这个设置作斗争,为了让它工作,我必须做一些与上述文章略有不同的事情。

Posting here because google kept bringing me back here....

在这里发帖是因为谷歌一直把我带回这里......

Full instructions posted here

完整说明张贴在这里

I followed a combination of these instructionsand these (in the source)

我遵循了这些说明这些(在源代码中)的组合

The main differences are that I had to do the "pure python" install of mercurialotherwise it would complain about missing dlls, and I found it was important to use the "python installers" for pywin and isapi-wsgi. (maybe this is obvious to experienced python developers, but I'm a python newbie so it was news to me)

主要区别在于我必须对mercurial进行“纯 python”安装,否则它会抱怨缺少 dll,而且我发现使用 pywin 和 isapi-wsgi 的“python 安装程序”很重要。(也许这对于有经验的 Python 开发人员来说是显而易见的,但我是一个 Python 新手,所以这对我来说是新闻)

Hope this helps somebody and I'm not just making stuff up (I might be, like i said, python newbie)

希望这对某人有所帮助,而且我不仅仅是在编造东西(我可能是,就像我说的,python 新手)

回答by Tony Yates

I was running into a "...can not load module..." type error and after some reading, the key for me was to ignore the Library.zip file in the Mercurial folder, and instead use the one from C:\Program Files (x86)\TortoiseHg folder.

我遇到了“...无法加载模块...”类型错误,经过一些阅读后,我的关键是忽略 Mercurial 文件夹中的 Library.zip 文件,而是使用 C:\ Program Files (x86)\TortoiseHg 文件夹。

That tip I found as #6 in this guide:

我在本指南中发现的第 6 条提示:

http://www.endswithsaurus.com/2010/05/setting-up-and-configuring-mercurial-in.html

http://www.endswithsaurus.com/2010/05/setting-up-and-configuring-mercurial-in.html

Hope this helps someone...

希望这可以帮助某人...

回答by Kevin Berridge

The hg red book contains some much better general instructions than I've seen in other places. They are not IIS specific, but they are quite good:

hg 红皮书包含一些比我在其他地方看到的更好的一般说明。它们不是特定于 IIS 的,但它们非常好:

http://hgbook.red-bean.com/read/collaborating-with-other-people.html#sec:collab:cgi

http://hgbook.red-bean.com/read/collaborating-with-other-people.html#sec:collab:cgi

回答by Anton Gogolev

You can try HgLab. This isn't exactly hgwebdir; rather it is a purely managed Mercurial implementation with push and pull server and repository browser.

你可以试试HgLab。这不完全是 hgwebdir;相反,它是一个带有推拉服务器和存储库浏览器的纯托管 Mercurial 实现。