How to get gitolite / gitweb working together?

孤人 提交于 2019-12-02 05:49:42

As the OP mentions in the comment, you need to make sure your VirtulaHost in the Apache config calls gitweb.cgi with the right parameters/environment variables:

Here is my httpd.conf for that service:
Notice how it will avoid ScriptAliasMatch and how it does set GIT_HTTP_BACKEND.

# GitWeb on 8443 # or any port you want
Listen 8443
<VirtualHost hostname>
    ServerName hostname
    ServerAlias short-hostname
    SSLCertificateFile "/path/to/apache/crt"
    SSLCertificateKeyFile "/path/to/apache/key"
    SSLEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SetEnv GIT_HTTP_BACKEND /path/to/git/libexec/git-core/git-http-backend
    DocumentRoot /path/to/gitweb
    Alias /gitweb /path/to/gitweb
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
      SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /path/to/gitweb>
        SSLOptions +StdEnvVars
        Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
        AllowOverride All
        order allow,deny
        Allow from all

        AuthName "LDAP authentication for GitWeb repositories"
        AuthType Basic
        AuthBasicProvider myldap companyldap
        AuthzLDAPAuthoritative On
        Require valid-user

        AddHandler cgi-script cgi
        DirectoryIndex gitweb.cgi

        RewriteEngine Off
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^[a-zA-Z0-9_\-]+\.git/?(\?.*)?$ /gitweb.cgi%{REQUEST_URI} [L,PT]
    </Directory>
</VirtualHost>

Original answer:

Here is my gitweb.conf.pl:

my $gl_home = $ENV{HOME} = "@H@";

# the following variables are needed by gitolite; please edit before using

# this should normally not be anything else
$ENV{GL_RC} = "$gl_home/.gitolite.rc";
# this can have different values depending on how you installed.

# if you used RPM/DEB or "root" methods it **might** be this:
$ENV{GL_BINDIR} = "/usr/local/bin";
# if you used the "non-root" method it **might** be this:
$ENV{GL_BINDIR} = "$gl_home/gitolite/bin";
# If in doubt take a look at ~/.ssh/authorized_keys; at least one of the lines
# might contain something like:
#       command="/home/git/.gitolite/src/gl-auth-command
# and you should use whatever directory the gl-auth-command is in (in this
# example /home/git/.gitolite.src)

# finally the user name
$ENV{GL_USER} = $cgi->remote_user || "gitweb";

# now get gitolite stuff in...
unshift @INC, $ENV{GL_BINDIR};
require gitolite_rc;    gitolite_rc -> import;
require gitolite;       gitolite    -> import;

# set project root etc. absolute paths
$ENV{GL_REPO_BASE_ABS} = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$gl_home/$REPO_BASE" );
$projects_list = $projectroot = $ENV{GL_REPO_BASE_ABS};

$export_auth_hook = sub {
    my $repo = shift;
    # gitweb passes us the full repo path; so we strip the beginning
    # and the end, to get the repo name as it is specified in gitolite conf
    return unless $repo =~ s/^\Q$projectroot\E\/?(.+)\.git$/$1/;

    # check for (at least) "R" permission
    my ($perm, $creator) = &repo_rights($repo);
    return ($perm =~ /R/);
};

Replace the @H@ by your path where your .gitolite, .gitoliterc, repositories, project.list files are.

Note how I defined $ENV{GL_BINDIR}: I didn't comment the second definition, because in my case I did a non-root installation, hence the:

$ENV{GL_BINDIR} = "$gl_home/gitolite/bin";

Make sure to have a gitweb_config.perl with:

our $home_link_str = "ITSVC projects";
our $site_name = "ITSVC Gitweb";

use lib (".");
require "gitweb.conf.pl";

That is what will make the link between gitweb and the extra gitweb.conf.pl which will call gitolite.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!