git-http-backend返回错误502 [英] git-http-backend returns error 502

查看:623
本文介绍了git-http-backend返回错误502的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的服务器上运行gitweb和gitolite: http://git.jshawl.com/



我无法设置 git-http-backend 以允许匿名克隆。



以下是我的vhosts文件( /etc/apache2/extra/httpd-vhosts.conf )的外观:

 < VirtualHost *:80> 
DocumentRoot/ Users / git / repositories
ServerName git.jshawl.com
<目录/ Users / git / repositories>
选项ExecCGI + FollowSymLinks + SymLinksIfOwnerMatch
AllowOverride全部
允许,拒绝
允许全部
AddHandler cgi-script cgi
DirectoryIndex gitweb.cgi
< / Directory>

< LocationMatch^ /。* / git-receive-pack $>
AuthType Basic
AuthNameGit Access
需要组提交者
< / LocationMatch

SetEnv GIT_PROJECT_ROOT / Users / 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))$\
/ usr / libexec / git-core / git-http- backend / $ 1

ScriptAlias / /Users/git/repositories/gitweb.cgi/





我遵循这里的指示: http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html ,但我一直在面对与502错误。

我的apache错误日志说: [Fri Aug 24 19:29:32 2012] [error] [client 198.228.200.148] client denied by服务器配置:/ usr / libexec / git-core / git -http-backend



另外,添加所有这一切后,我的gitweb安装(曾经在 http://git.jshawl.com



我做错了什么?

解决方案

这里是这个 httpd.conf 中的另一种方法,适用于克隆/推送/但不会调用gitweb.cgi



GitWeb用于浏览,而不是用于克隆



(小提取,移除验证详细信息和SSL细节)

 #GitHttp @ PORT_HTTP_HGIT @ 
Listen @ PORT_HTTP_HGIT @
< VirtualHost @FQN @:@ PORT_HTTP_HGIT @>
ServerName @ FQN @
ServerAlias @ HOSTNAME @
SetEnv GIT_PROJECT_ROOT @ H @ /存储库
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv GITOLITE_HTTP_HOME @ H @
ScriptAlias / hgit / @ H @ / gitolite / bin / gitolite-shell /
SetEnv GIT_HTTP_BACKEND@ H @ / usr / local / apps / git / libexec / git-core / git-http-backend
< FilesMatch \(CGI | SHTML | PHTML | PHP)$。 >
SSLOptions + StdEnvVars
< / FilesMatch>
< Location / hgit>
AddHandler cgi-script cgi
< / Location>
< / VirtualHost>

换言之:


  • git-http-backend 被变量 GIT_HTTP_BACKEND 引用,但 you won'如果您使用的是Gitolite V3,那就需要它。

  • gitolite-shell 当您使用 / hgit / 在您的克隆地址中:theat GitoliteV3脚本将检查您是否有权克隆回购,如果是,将调用脚本后面的命令 git-http-backend git-receive-pack '(for push)or' git-upload-pack '(用于clone / pull / fetch),直接从git源文件本身 http-backend.c


所以:

  git clone https:// yourServer / hgit / yourRep o 

会调用gitolite,它会调用' git-receive-pack '或' git-upload-pack '。

它将首先通过调用 sub http_simulate_ssh_connection()


  sub http_simulate_ssh_connection {
#这些模式表示正常的git使用情况;请参阅
#http-backend.c中的services [],了解我如何得到它。另请注意,信息已过载;
#git使用info / refs ...,而gitolite使用info或info?...。所以
#在
下面的列表中有一个/,如果($ ENV {PATH_INFO} =〜m(^ /(。*)/(HEAD $ | info / refs $ | objects / | git - (?: upload | receive)-pack $))){
my $ repo = $ 1;
my $ verb =($ ENV {REQUEST_URI} =〜/ git-receive-pack /)? 'git-receive-pack':'git-upload-pack';
$ ENV {SSH_ORIGINAL_COMMAND} =$ verb'$ repo';
} else {
#这是我们的自定义命令之一;因为adc功能
my($ verb)=($ ENV {PATH_INFO} =〜m(^ /(\S +)));
my $ args = $ ENV {QUERY_STRING};
$ args =〜s / \ + / / g;
$ args =〜s /%([0-9A-Fa-f] {2})/ chr(hex($ 1))/ eg;
$ ENV {SSH_ORIGINAL_COMMAND} = $ verb;
$ ENV {SSH_ORIGINAL_COMMAND}。=$ argsif $ args;
http_print_headers(); #为最终输出做准备!
}
$ ENV {SSH_CONNECTION} =$ ENV {REMOTE_ADDR} $ ENV {REMOTE_PORT} $ ENV {SERVER_ADDR} $ ENV {SERVER_PORT};
}


I'm running gitweb and gitolite on my server: http://git.jshawl.com/

I'm having trouble setting up the git-http-backend to allow anonymous cloning.

Here's what my vhosts file (/etc/apache2/extra/httpd-vhosts.conf) looks like:

<VirtualHost *:80>
DocumentRoot "/Users/git/repositories"
ServerName git.jshawl.com
 <Directory "/Users/git/repositories">
    Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
    AllowOverride All
    order allow,deny
    Allow from all
    AddHandler cgi-script cgi
    DirectoryIndex gitweb.cgi
</Directory>

<LocationMatch "^/.*/git-receive-pack$">
    AuthType Basic
    AuthName "Git Access"
    Require group committers
</LocationMatch

SetEnv GIT_PROJECT_ROOT /Users/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))$" \
    /usr/libexec/git-core/git-http-backend/$1

ScriptAlias / /Users/git/repositories/gitweb.cgi/

`

I followed the directions here: http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html, but am consistently confronted with that 502 error.

My apache error log says: [Fri Aug 24 19:29:32 2012] [error] [client 198.228.200.148] client denied by server configuration: /usr/libexec/git-core/git-http-backend

Also, adding all of this has taken down my gitweb installation (which used to be at http://git.jshawl.com)

What am I doing wrong?

解决方案

Here is another approach in this httpd.conf which works well for cloning/pushing/pulling, but it doesn't call gitweb.cgi:

GitWeb is for browsing, not for cloning

(small extract, removing Auth details, and SSL details)

# GitHttp on @PORT_HTTP_HGIT@
Listen @PORT_HTTP_HGIT@
<VirtualHost @FQN@:@PORT_HTTP_HGIT@>
  ServerName @FQN@
  ServerAlias @HOSTNAME@
  SetEnv GIT_PROJECT_ROOT @H@/repositories
  SetEnv GIT_HTTP_EXPORT_ALL
  SetEnv GITOLITE_HTTP_HOME @H@
  ScriptAlias /hgit/ @H@/gitolite/bin/gitolite-shell/
  SetEnv GIT_HTTP_BACKEND "@H@/usr/local/apps/git/libexec/git-core/git-http-backend"
  <FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
  </FilesMatch>
  <Location /hgit>
    AddHandler cgi-script cgi
  </Location>
</VirtualHost>

In other words:

  • git-http-backend is referenced by the variable GIT_HTTP_BACKEND, but you won't need it if you are using Gitolite V3.
  • gitolite-shell is called when you are using /hgit/ in your cloning address: theat GitoliteV3 script will check if you have the right to clone the repo, and if yes, will call the commands behind the script git-http-backend: 'git-receive-pack' (for push) or 'git-upload-pack' (for clone/pull/fetch), straight from the git source itself http-backend.c.

So:

git clone https://yourServer/hgit/yourRepo

Will call gitolite, which will call 'git-receive-pack' or 'git-upload-pack'.
It will first analyze the http request by calling sub http_simulate_ssh_connection()

sub http_simulate_ssh_connection {
    # these patterns indicate normal git usage; see "services[]" in
    # http-backend.c for how I got that. Also note that "info" is overloaded;
    # git uses "info/refs...", while gitolite uses "info" or "info?...". So
    # there's a "/" after info in the list below
    if ( $ENV{PATH_INFO} =~ m(^/(.*)/(HEAD$|info/refs$|objects/|git-(?:upload|receive)-pack$)) ) {
        my $repo = $1;
        my $verb = ( $ENV{REQUEST_URI} =~ /git-receive-pack/ ) ? 'git-receive-pack' : 'git-upload-pack';
        $ENV{SSH_ORIGINAL_COMMAND} = "$verb '$repo'";
    } else {
        # this is one of our custom commands; could be anything really,
        # because of the adc feature
        my ($verb) = ( $ENV{PATH_INFO} =~ m(^/(\S+)) );
        my $args = $ENV{QUERY_STRING};
        $args =~ s/\+/ /g;
        $args =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
        $ENV{SSH_ORIGINAL_COMMAND} = $verb;
        $ENV{SSH_ORIGINAL_COMMAND} .= " $args" if $args;
        http_print_headers(); # in preparation for the eventual output!
    }
    $ENV{SSH_CONNECTION} = "$ENV{REMOTE_ADDR} $ENV{REMOTE_PORT} $ENV{SERVER_ADDR} $ENV{SERVER_PORT}";
}

这篇关于git-http-backend返回错误502的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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