【问题标题】:Setting up Git Server on Windows With git-http-backend.exe使用 git-http-backend.exe 在 Windows 上设置 Git 服务器
【发布时间】:2010-09-28 22:28:31
【问题描述】:

我正在使用 Apache 和 git-http-backend.exe 在 WS 2008 机器上设置 Git 服务器 (1.7.2.3)。我一直很关注here。我有 GUI 工作,我可以无声地克隆,如果我将以下内容放入 repo 的配置中,我可以无声地推送:

[http]
 receivepack = true

我在 httpd.conf 文件中添加了以下内容:

SetEnv GIT_PROJECT_ROOT C:/GIT/Repositories
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAliasMatch \
        "(?x)^/(.*/(HEAD | \
                    info/refs | \
                    objects/(info/[^/]+ | \
                             [0-9a-f]{2}/[0-9a-f]{38} | \
                             pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                    git-(upload|receive)-pack))$" \
                    "C:/Program Files (x86)/git/libexec/git-core/git-http-backend.exe/$1"

<Directory />
  Allow from all
</Directory>

<LocationMatch "^/git/.*/git-receive-pack$">
        AuthType Basic
        AuthName "Git Access"
  AuthUserFile C:/GIT/ApacheConfig/users
  AuthGroupFile  C:/GIT/ApacheConfig/groups
        Require group repogeneral        
</LocationMatch>

当我添加“LocationMatch”时,我仍然可以匿名克隆或通过在 URL 中指定名称,git clone http://jon@myserver.com

它会提示输入密码并克隆。

但是当我尝试推回回购时,我得到以下信息:

错误:无法访问 URL http://jon@myserver.com/newtestrepo.git/,返回代码 22 致命:git-http-push 失败

我一直在查看http-backend.exe man page 的示例,但无法让它们发挥作用。

这是我的组文件,(这只是测试示例,因此不会在产品中使用):

admin: jon steve admin
webview: jon steve web
repogeneral: jon steve
testrepo: jon admin
testrepo2: jon steve web

这里是用户文件:

jon:$apr1$kEKVExYx$guIF9oYV8buGhFLZr16XN0
steve:$apr1$jvgjF9nv$PvWsHH.cSOBN5ymk6NT1B0
admin:$apr1$vzXgDskN$oszCei3tkHNUgtLj2HkHF/
web:$apr1$wS0do7hb$VA9tsc9c9LwY5PcjfhdwK0

我知道用户名 jon 就像我将目录要求放在 gui 部分一样,我可以使用用户名 jon 登录没问题,(与 locationmatch 指向相同的用户和组文件)。

我不确定此时我错过了什么配置(假设是配置问题)。

任何关于克服最后一个障碍的建议都很棒。

编辑

我又玩了一些,以下是我掌握的信息:

如果我克隆一个回购:

git clone http://jon@myserver.com/remotetest.git

我可以将存储库取出,但是当我尝试使用以下命令推回时:

git push origin master

我被要求输入密码,我输入它,然后它再次要求输入密码,然后我收到以下错误:

C:\temp\remotetest\remotetest>git push origin master 密码: 密码: 错误:无法访问 URL http://jon@myserver.com/remotetest.git/,返回代码 22 致命:git-http-push 失败

在我的 Apache access.log 中,我得到以下信息:

192.168.1.2 - - [29/Sep/2010:21:58:19 +0100] "GET /remotetest.git/info/refs?service=git-upload-pack HTTP/1.1" 200 38
192.168.1.2 - - [29/Sep/2010:21:58:51 +0100] "GET /remotetest.git/info/refs?service=git-receive-pack HTTP/1.1" 403 -
192.168.1.2 - - [29/Sep/2010:21:58:51 +0100] "GET /remotetest.git/info/refs HTTP/1.1" 200 -
192.168.1.2 - - [29/Sep/2010:21:58:51 +0100] "GET /remotetest.git/HEAD HTTP/1.1" 200 23

有趣的是,当我使用 URL 中的用户名进行克隆时,无论我输入什么密码,它仍然可以工作。我假设这是因为我应该能够匿名拉取。不知道为什么它会要求输入密码。

我在日志中也看到了这个错误:

[Wed Sep 29 22:33:00 2010] [error] [client 192.168.1.2] client denied by server configuration: C:/Program Files (x86)/Git/libexec/git-core/git-http-backend.exe
[Wed Sep 29 22:33:00 2010] [error] [client 192.168.1.2] client denied by server configuration: C:/Program Files (x86)/Git/libexec/git-core/git-http-backend.exe

编辑 2

我尝试通过以下方式重新创建密码文件:

htpasswd -c -m C:/git/apacheconfig/users jon

但这没有帮助。

编辑 3

httpd.conf 中的 PHP 配置,它使用相同的用户文件进行基本身份验证:

<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
    AuthName "GitUsers"
    AuthType Basic
    AuthUserFile C:/GIT/ApacheConfig/users
AuthGroupFile  C:/GIT/ApacheConfig/groups

    require group webview
</Directory>

编辑 4

好的,这样我就可以愉快地在匿名模式下进行克隆和推送了,但是推送的身份验证失败。

C:\temp\test2\temp\test>git push origin master
Password:
Password:
error: Cannot access URL http://jon@192.168.10.97:8000/repositories/test.git/, return code 22
fatal: git-http-push failed

我更改了 httpd.conf 以使用以下内容:

<VirtualHost *:80>
    SetEnv GIT_PROJECT_ROOT "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/repositories"
    SetEnv GIT_HTTP_EXPORT_ALL

    <Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/repositories">
       Options Indexes FollowSymLinks MultiViews Includes ExecCGI
       AllowOverride None
       Order allow,deny
       Allow from all
    </Directory>

    <LocationMatch "^/repositories/.*/git-receive-pack$">
        AuthType Basic
        AuthName "Git Access"
        AuthUserFile "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/repositories/.htpasswd"
        Require valid-user
    </LocationMatch>
    ScriptAliasMatch \
            "(?x)^/repositories/(.*/(HEAD | \
                            info/refs | \
                            objects/(info/[^/]+ | \
                                     [0-9a-f]{2}/[0-9a-f]{38} | \
                                     pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                            git-(upload|receive)-pack))$" \
            "C:/Program Files (x86)/Git/libexec/git-core/git-http-backend/$1"

    ErrorLog C:/GIT/error_log
    CustomLog C:/GIT/access_log combined
</VirtualHost>

有趣的是,当我创建一个新的 repo (git init --bare newrepo.git) 时,它并没有创建 info/refs 文件。我必须执行“git update-server-info”命令来创建它。

Apache Access 日志中有一些有趣的东西可能是一个线索:

192.168.10.97 - - [05/Oct/2010:22:48:26 +0100] "GET /repositories/test.git/info/refs?service=git-receive-pack HTTP/1.1" 200 -
192.168.10.97 - - [05/Oct/2010:22:48:26 +0100] "GET /repositories/test.git/HEAD HTTP/1.1" 200 23
192.168.10.97 - - [05/Oct/2010:22:48:28 +0100] "PROPFIND /repositories/test.git/ HTTP/1.1" 405 248

那是我试图“推”回回购的时候,但它们是 GET 命令而不是 POST。不确定 PROPFIND 是什么,还没有找到太多关于它的信息。我认为,(四处阅读)可能会进行某种重写,即将 POST 更改为 GET 并杀死它,或者其他什么。不过,此时我已经超出了我的深度。

谢谢

【问题讨论】:

  • 我不知道为什么“htdocs”以Directorydefinition 的形式出现在图片中。
  • 这是 Apache 提供文件的默认位置。我使用 PHP gui 来显示存储库,它使用相同的 authuserfile 并提供弹出登录名并使用相同的用户名和密码。使用它作为测试以确保 Apache 可以理解用户密码文件。
  • 这个问题应该在serverfault.com 上,因为它涉及的编程较少,而更多涉及设置和配置,不是吗?
  • 我确实考虑过这个问题,但我在 stackoverflow 上发现的 git 问题与我在 ServerFault 上的问题一样多。

标签: git apache2 git-http-backend


【解决方案1】:

好的,地狱已经结冰了,我终于搞定了!

我认为我的设置存在两点根本错误。

1) 用户没有通过身份验证,我发现这有帮助:

SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER

其次,我无法让物理“目录”工作。

<Directory "C:/GIT/Apache/repositories">
Options +ExecCGI
AuthType Basic
AuthName intranet
AuthUserFile "C:/GIT/Apache/config/users"
Require valid-user
</Directory>

为了解决这个问题,我将 locationMatch 用于拉取和推送。这意味着您必须进行身份验证才能拉取和推送。如果你想烦人拉你可以删除“git-upload-pack”部分。

希望这对其他人有帮助。

这是我最终的 httpd.conf 文件:

DocumentRoot "C:/GIT/Apache/www"

<Directory />
Options +ExecCGI
Allow from all  
</Directory>

<Directory "C:/GIT/Apache/www">
  Allow from all
</Directory>

<Directory "C:/GIT/Apache/www/secure">
AuthType Basic
AuthName intranet
AuthUserFile "C:/GIT/Apache/config/users"
require valid-user
</Directory>

SetEnv GIT_PROJECT_ROOT C:/GIT/Apache/repositories
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
ScriptAliasMatch \
    "(?x)^/(.*/(HEAD | \
                    info/refs | \
                    objects/(info/[^/]+ | \
                             [0-9a-f]{2}/[0-9a-f]{38} | \
                             pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                    git-(upload|receive)-pack))$" \
                    "C:/Program Files/git/libexec/git-core/git-http-backend.exe/$1"


<LocationMatch "^/.*/git-receive-pack$">
Options +ExecCGI
AuthType Basic
AuthName intranet
AuthUserFile "C:/GIT/Apache/config/users"
Require valid-user
</LocationMatch>

<LocationMatch "^/.*/git-upload-pack$">
Options +ExecCGI
AuthType Basic
AuthName intranet
AuthUserFile "C:/GIT/Apache/config/users"
Require valid-user
</LocationMatch>

【讨论】:

  • 优秀的反馈。谢谢你。 +1
  • 嗨,乔恩,你的工作非常棒。你能帮我理解你是如何管理用户配置的吗,因为这对你来说似乎不是问题
  • @pollux1er 最后我搬到了 github。我只是为自己使用它,所以对用户没有太多担心。现在想不起来了,对不起,GL。
  • 感谢 @Jon 为您提供 Quastion 和您自己的 Awnser,但我在自测中发现您的配置文件中存在一些错误。您需要将完整的位置添加到您的AuthUserFile。如果没有这个,你会一遍又一遍地遇到像这样的 500 错误AH01620: Could not open password file 我的解决方案:AuthUserFile "C:/GIT/Apache/config/users/.htaccess"
猜你喜欢
  • 1970-01-01
  • 2012-09-27
  • 2017-01-31
  • 1970-01-01
  • 2012-05-20
  • 2013-03-09
  • 1970-01-01
  • 2023-03-23
相关资源
最近更新 更多