git-http-后端

标签 git apache git-http-backend

我尝试用 git-http-backend 设置一个 git 服务器,一切都按我想要的方式运行,但有一件小事。

配置

<VirtualHost *:80>
ServerName git.server.com
SetEnv GIT_PROJECT_ROOT /srv/git
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
ScriptAlias /git /usr/lib/git-core/git-http-backend/

<Directory "/usr/lib/git-core*">
   Options ExecCGI Indexes
   Order allow,deny
   Allow from all
</Directory>

<LocationMatch "^/git/repos/git-receive-pack$">
  AuthType Digest
  AuthName "Git Repositories"
  AuthUserFile /srv/git/.git-auth-file
  AuthGroupFile /srv/git/.git-group-file
  Require valid-user
</LocationMatch>
</VirtualHost>

这允许每个人都可以阅读存储库,但只有有效用户才能写入。让我烦恼的是 url 是 http://git.server.com/git/repos .我想去掉 URL 中的 git,例如 http://git.server.com/repos .当我将配置更改为

<VirtualHost *:80>
ServerName git.server.com
SetEnv GIT_PROJECT_ROOT /srv/git
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
ScriptAlias / /usr/lib/git-core/git-http-backend/

<Directory "/usr/lib/git-core*">
   Options ExecCGI Indexes
   Order allow,deny
   Allow from all
</Directory>

<LocationMatch "^/repos/git-receive-pack$">
  AuthType Digest
  AuthName "Git Repositories"
  AuthUserFile /srv/git/.git-auth-file
  AuthGroupFile /srv/git/.git-group-file
  Require valid-user
</LocationMatch>
</VirtualHost>

认证失败。我仍然可以阅读存储库,但 git push 失败了。我不明白为什么会这样。

* About to connect() to git.server.com port 80 (#0)
*   Trying MYIP... * Connected to git.server.com (MYIP) port 80 (#0)
> GET /iocaste/info/refs?service=git-receive-pack HTTP/1.1
User-Agent: git/1.7.6
Host: git.server.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 200 OK
< Date: Sun, 28 Aug 2011 18:17:27 GMT
< Server: Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/1.0.0d DAV/2 PHP/5.3.8 with Suhosin-Patch SVN/1.6.17
< Expires: Fri, 01 Jan 1980 00:00:00 GMT
< Pragma: no-cache
< Cache-Control: no-cache, max-age=0, must-revalidate
< Transfer-Encoding: chunked
< Content-Type: application/x-git-receive-pack-advertisement
< 
* Connection #0 to host git.server.com left intact
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 257 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
* About to connect() to git.server.com port 80 (#0)
*   Trying MYIP... * connected
* Connected to git.server.com (MYIP) port 80 (#0)
> POST /iocaste/git-receive-pack HTTP/1.1
User-Agent: git/1.7.6
Host: git.server.com
Accept-Encoding: deflate, gzip
Content-Type: application/x-git-receive-pack-request
Accept: application/x-git-receive-pack-result
Content-Length: 393

* The requested URL returned error: 404
* Closing connection #0
error: RPC failed; result=22, HTTP code = 404
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly

有人可以帮我理解为什么后者会失败吗?我假设一定是 ScriptAlias 在身份验证期间启动。

编辑 1 apache 的日志记录并没有给我太多信息。只是由于某种原因身份验证失败。

access_log 说:

MYIP - - [29/Aug/2011:19:03:18 +0200] "GET /repos/info/refs?service=git-receive-pack HTTP/1.1" 200 153
MYIP - - [29/Aug/2011:19:03:18 +0200] "POST /repos/git-receive-pack HTTP/1.1" 404 - 

error_log 说:

[Mon Aug 29 19:03:18 2011] [error] [client MYIP] Request not supported:   '/srv/git/error/HTTP_UNAUTHORIZED.html.var'

最佳答案

尝试改变

ScriptAlias / /usr/lib/git-core/git-http-backend/

更智能的匹配,只将 git 请求定向到 git-http-backend:

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))$" \
     /usr/lib/git-core/git-http-backend/

关于git-http-后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7222992/

相关文章:

php - 几秒钟的延迟 apache 响应

git - Apache 和 git-http-backend

git - 如何解决 Git-TFS verify 发现的差异

apache - 将 script.js 重定向到 script.php

git - 我如何使用 BitBucket+Git+Maven 发布

apache - 子域的 SSL 允许父域重定向到子域

Git push 在写入对象时卡住并给出 504 错误

git - 如何通过 http 设置 git?

git - 我如何用 jgit 做相当于 “git remote update” 的操作?

macos - 删除.git/index.lock' : Permission denied