使用 git-http-backend.exe 在 Windows 上设置 Git 服务器 [英] Setting up Git Server on Windows With git-http-backend.exe

查看:51
本文介绍了使用 git-http-backend.exe 在 Windows 上设置 Git 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Apache 和 git-http-backend.exe 在 WS 2008 机器上设置 Git 服务器 (1.7.2.3).我一直在关注一个很好的 tut 此处.我的 GUI 可以正常工作,我可以麻烦地克隆,如果我将以下内容放入存储库的配置中,我可以麻烦地推送:

I am in the process of setting up a Git server (1.7.2.3) on a WS 2008 machine using Apache and git-http-backend.exe. I have been following a good tut here. I have the GUI working, I can annoymously clone and if I put the following in the config of a repo I can annoymously push:

[http]
 receivepack = true

我已将以下内容添加到 httpd.conf 文件中:

I have added the following to the httpd.conf file:

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

When I add the "LocationMatch" I can still clone annoymously or by specifying a name in the URL, git clone http://jon@myserver.com

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

It will prompt for a password and clone.

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

but when I try to push back to the repo I get the following:

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

error: Cannot access URL http://jon@myserver.com/newtestrepo.git/, return code 22 fatal: git-http-push failed

我一直在查看 http-backend.exe 手册页示例,但无法使它们工作.

I have been looking at the http-backend.exe man page for examples but can not get them to work.

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

here is my groups file, (this is just testing out examples so nothing that would be used in prod):

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 相同的用户和组文件).

I know the username jon works as if I put the directory requirement on the gui section I can login with the username jon no problem, (points at the same user and group files as the locationmatch does).

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

I am not sure what configuration I have missed off at this point, (assuming its a configuration issue).

任何关于克服这最后障碍的建议都很棒.

Any advice on getting over this last hurdle would be fantastic.

编辑

我已经玩了更多,以下是我掌握的信息:

I have been playing some more and here is the information I have:

如果我克隆了一个仓库:

if I clone a repo with:

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

我可以取出存储库,但是当我尝试用以下方法推回时:

I can get the repository out, but when I try and push back with:

git push origin master

git push origin master

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

I get asked for my password, I enter it, then it asks for it again, then I get the following error:

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

C:\temp\remotetest\remotetest>git push origin master Password: Password: error: Cannot access URL http://jon@myserver.com/remotetest.git/, return code 22 fatal: git-http-push failed

在我的 Apache access.log 中,我得到以下内容:

In my Apache access.log I get the following:

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 中的用户名进行克隆时,我输入的密码并不重要,它仍然可以工作.我假设这是因为我应该能够匿名拉.不知道为什么它当时要求输入密码.

Interestingly when I clone with the username in the URL it doesn't matter what password I put in, it will still work. I am assuming this is because I should be able to pull anonymously. Not sure why it asks for a password at all at that point.

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

I also see this in the logs error:

[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

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

I tried recreating the password file by doing:

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

但这没有帮助.

编辑 3

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

the PHP config in httpd.conf where it uses the same users file for basic auth:

<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

好的,这样我就可以愉快地以恼人的模式进行克隆和推送,但是推送的身份验证失败.

OK so I can get to cloning and pushing in annoymous mode happily, but authentication fails for the push.

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 以使用以下内容:

I changed the httpd.conf to use the following:

<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"命令来创建它.

Interestingly, when I created a new repo (git init --bare newrepo.git) It didn't create a info/refs file. I had to do the "git update-server-info" command to create that.

Apache Access 日志中有一些有趣的东西可以作为线索:

The Apache Access logs have something interesting that could be a clue:

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

那是我试图推"回 repo 的时候,但它们是 GET 命令而不是 POST.不确定 PROPFIND 是什么,还没有找到太多相关信息.我认为,(四处阅读),可能会发生某种重写,即将 POST 更改为 GET 并杀死它,或其他什么.不过,我在这一点上超出了我的深度.

That is when I was trying to "push" back to the repo, but they are GET commands and no POST. not sure what the PROPFIND is, not found much info on that yet. I think, (reading around), there might be some sort of rewrite going on, that is changing the POST to a GET and killing it, or something. I am out of my depth at this point though.

谢谢

推荐答案

好吧,地狱已经冻结了,我终于开始工作了!

OK, so hell has frozen over and I have finally got this working!

我认为我的设置有两个根本性的错误.

I believe there were two things that were fundamentally wrong with my setup.

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

1) The user was not getting authentication passed through, I found this helped:

SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER

其次,我无法让物理目录"工作.

Secondly I couldn't get the physical "Directory" to work.

<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"部分.

To resolve this I used locationMatch for both the pull and push. This means you have to authenticate to pull and push. If you wanted annoy pulling you can remove the "git-upload-pack" section.

希望这可以帮助其他人.

Hope this may help someone else.

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

Here is my final httpd.conf file:

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>

这篇关于使用 git-http-backend.exe 在 Windows 上设置 Git 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆