git-http-backend returns error 502

前端 未结 1 1762
梦谈多话
梦谈多话 2021-01-24 15:18

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.

<
相关标签:
1条回答
  • 2021-01-24 15:22

    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}";
    }
    
    0 讨论(0)
提交回复
热议问题