使用 git-http-backend.exe 在 Windows 上设置 Git 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3817478/
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-10 09:10:57  来源:igfitidea点击:

Setting up Git Server on Windows With git-http-backend.exe

gitapache2git-http-backend

提问by Jon

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:

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

[http]
 receivepack = true

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

我已将以下内容添加到 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/"

<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>

When I add the "LocationMatch" I can still clone annoymously or by specifying a name in the URL, git clone http://[email protected]

当我添加“LocationMatch”时,我仍然可以通过在 URL 中指定名称来进行克隆,git clone http://[email protected]

It will prompt for a password and clone.

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

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

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

error: Cannot access URL http://[email protected]/newtestrepo.git/, return code 22 fatal: git-http-push failed

错误:无法访问 URL http://[email protected]/newtestrepo.git/,返回代码 22 致命:git-http-push failed

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

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

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

here is the users file:

这是用户文件:

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

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).

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

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.

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

EDIT

编辑

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

我一直在玩更多,这里是我的信息:

if I clone a repo with:

如果我克隆一个 repo:

git clone http://[email protected]/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 Password: Password: error: Cannot access URL http://[email protected]/remotetest.git/, return code 22 fatal: git-http-push failed

C:\temp\remotetest\remotetest>git push origin master 密码:密码:错误:无法访问 URL http://[email protected]/remotetest.git/,返回码 22 致命:git-http-push failed

In my Apache access.log I get the following:

在我的 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

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.

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

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

EDIT 2

编辑 2

I tried recreating the password file by doing:

我尝试通过执行以下操作重新创建密码文件:

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

but this didn't help.

但这没有帮助。

EDIT 3

编辑 3

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

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>

EDIT 4

编辑 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://[email protected]:8000/repositories/test.git/, return code 22
fatal: git-http-push failed

I changed the httpd.conf to use the following:

我更改了 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/"

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

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.

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

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

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

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.

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

Thanks

谢谢

回答by Jon

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) The user was not getting authentication passed through, I found this helped:

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

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>

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.

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

Hope this may help someone else.

希望这可以帮助别人。

Here is my final httpd.conf file:

这是我的最终 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/"


<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>