【问题标题】:gitweb 404 - No projects foundgitweb 404 - 未找到项目
【发布时间】:2012-08-24 20:20:41
【问题描述】:

我在 Ubuntu 12.04 服务器上安装了 git + gitolite + git-daemon + gitweb setup。 问题是我总是得到 404 - 找不到项目。 我添加了一个名为 git 的用户并配置了 gitolite。安装 git-web 后,将用户 www-data 添加到 gitolite 并将 project.list 的 chmod 设置为 g+r 并将存储库目录设置为 g+rx。

git@aranox~$ ls -al
total 44
drwxr-xr-x  6 git  git  4096 Aug 20 16:47 .
drwxr-xr-x 18 root root 4096 Aug 13 19:44 ..
-rw-------  1 git  git  1348 Aug 20 16:48 .bash_history
drwx------  2 git  git  4096 Aug 19 16:38 .cache
drwx------  8 git  git  4096 Aug 19 16:30 .gitolite
-rw-r--r--  1 git  git  4217 Aug 20 16:03 .gitolite.rc
-rw-r-----  1 git  git     0 Aug 20 16:05 projects.list
drwxr-x---  5 git  git  4096 Aug 19 16:49 repositories
drwx------  2 git  git  4096 Aug 20 16:05 .ssh
-rw-------  1 git  git   887 Aug 20 16:03 .viminfo

现在我将 .gitolite.rc 中的 $REPO_UMASK 更改为 0077 这是我的.gitolite.rc

# configuration variables for gitolite

# PLEASE READ THE DOCUMENTATION BEFORE EDITING OR ASKING QUESTIONS
# ( http://github.com/sitaramc/gitolite/blob/pu/doc/gitolite.rc.mkd )
#   ( or http://sitaramc.github.com/gitolite/doc/gitolite.rc.html )

# this file is in perl syntax.  However, you do NOT need to know perl to edit
# it; it should be fairly self-explanatory and easy to maintain

# ------------------------------------------------------------------------------
# DO NOT TOUCH THIS SECTION!
# ------------------------------------------------------------------------------

$GL_ADMINDIR=$ENV{HOME} . "/.gitolite";
$GL_CONF="$GL_ADMINDIR/conf/gitolite.conf";
$GL_KEYDIR="$GL_ADMINDIR/keydir";
$GL_CONF_COMPILED="$GL_ADMINDIR/conf/gitolite.conf-compiled.pm";

# DO NOT CHANGE THE NEXT FOUR LINES UNLESS YOU REALLY KNOW WHAT YOU'RE DOING.
# These variables are set automatically by the install method you choose.
#            (PACKAGE MAINTAINERS: PLEASE READ doc/packaging.mkd)
$GL_PACKAGE_CONF = "/usr/share/gitolite/conf";
$GL_PACKAGE_HOOKS = "/usr/share/gitolite/hooks";

# ------------------------------------------------------------------------------
# most often used/changed variables
# ------------------------------------------------------------------------------
$GL_WILDREPOS = 0;
$PROJECTS_LIST = $ENV{HOME} . "/projects.list";
# $WEB_INTERFACE = "gitweb";
# $GITWEB_URI_ESCAPE = 0;
$REPO_UMASK = 0027;

# ------------------------------------------------------------------------------
# variables with an efficiency/performance impact
# ------------------------------------------------------------------------------
$GL_BIG_CONFIG = 0;
$GL_NO_DAEMON_NO_GITWEB = 0;
# $GL_NICE_VALUE = 0;
# $BIG_INFO_CAP = 20;

# ------------------------------------------------------------------------------
# VARIABLES WITH A SECURITY IMPACT.  READ DOCS BEFORE CHANGING THESE!
# http://github.com/sitaramc/gitolite/blob/pu/doc/gitolite.rc.mkd#_variables_with_a_security_impact
# (or http://sitaramc.github.com/gitolite/doc/gitolite.rc.html#_variables_with_a_security_impact)
# ------------------------------------------------------------------------------
# $GL_ALL_READ_ALL = 0;
$GIT_PATH="";
$GL_GITCONFIG_KEYS = "";
$GL_NO_CREATE_REPOS = 0;
$GL_NO_SETUP_AUTHKEYS = 0;
# $GL_WILDREPOS_DEFPERMS = 'R @all';
$HTPASSWD_FILE = "";
$RSYNC_BASE = "";
$SVNSERVE = "";

# $UPDATE_CHAINS_TO = "hooks/update.secondary";
# $ADMIN_POST_UPDATE_CHAINS_TO = "hooks/post-update.secondary";
# $GL_ADC_PATH = "";
# $GL_GET_MEMBERSHIPS_PGM = "/usr/local/bin/expand-ldap-user-to-groups"
# $GL_HTTP_ANON_USER = "mob";
# $GL_REF_OR_FILENAME_PATT=qr(^[0-9a-zA-Z][0-9a-zA-Z._\@/+ :,-]*$);

# ------------------------------------------------------------------------------
# less used/changed variables
# ------------------------------------------------------------------------------
# $GL_ALL_INCLUDES_SPECIAL = 0;
# $GL_SLAVE_MODE = 0;
# $ENV{GL_SLAVES} = 'gitolite@server2 gitolite@server3';
# PLEASE USE SINGLE QUOTES ABOVE, NOT DOUBLE QUOTES
$GL_WILDREPOS_PERM_CATS = "READERS WRITERS";
# $GL_SITE_INFO = "XYZ.COM DEVELOPERS: PLEASE SEE http://xyz.com/gitolite/help first";
# $GL_HOSTNAME = "frodo";       # read doc/mirroring.mkd COMPLETELY before setting this

# ------------------------------------------------------------------------------
# rarely changed variables
# ------------------------------------------------------------------------------
$GL_LOGT="$GL_ADMINDIR/logs/gitolite-%y-%m.log";
# $GL_PERFLOGT="$GL_ADMINDIR/logs/perf-gitolite-%y-%m.log";

# ------------------------------------------------------------------------------
# variables that should NOT be changed after the install step completes
# ------------------------------------------------------------------------------
$REPO_BASE="repositories";

# ------------------------------------------------------------------------------
# DO NOT TOUCH ANY THING AFTER THIS LINE
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# per perl rules, this should be the last line in such a file:
1;

# Local variables:
# mode: perl
# End:
# vim: set syn=perl:

接下来更改了我的 /etc/gitweb.conf 的 $projectroot 和 $projects_list 并添加了一些配置。 这是我的 gitweb.conf

# path to git projects (<project>.git)
$projectroot = "/home/git/repositories";

# directory to use for temp files
$git_temp = "/tmp";

# target of the home link on top of all pages
#$home_link = $my_uri || "/";

# html text to include at home page
#$home_text = "indextext.html";

# file with project list; by default, simply scan the projectroot dir.
$projects_list = "/home/git/projects.list";

# stylesheet to use
#@stylesheets = ("static/gitweb.css");

# javascript code for gitweb
#$javascript = "static/gitweb.js";

# logo to use
#$logo = "static/git-logo.png";

# the 'favicon'
#$favicon = "static/git-favicon.png";

# git-diff-tree(1) options to use for generated patches
#@diff_opts = ("-M");
@diff_opts = ();


# Enable PATH_INFO so the server can produce URLs of the
# form: http://git.cdwilson.us/project.git/xxx/xxx
# This allows for pretty URLs *within* the Git repository, where
# my Apache rewrite rules are not active.
$feature{'pathinfo'}{'default'} = [1];

$projects_list_description_width = 100;

# Enable blame, pickaxe search, snapshop, search, and grep
# support, but still allow individual projects to turn them off.
# These are features that users can use to interact with your Git trees. They
# consume some CPU whenever a user uses them, so you can turn them off if you
# need to. Note that the 'override' option means that you can override the
# setting on a per-repository basis.
$feature{'blame'}{'default'} = [1];
$feature{'blame'}{'override'} = 1;

$feature{'pickaxe'}{'default'} = [1];
$feature{'pickaxe'}{'override'} = 1;

$feature{'snapshot'}{'default'} = [1];
$feature{'snapshot'}{'override'} = 1;

$feature{'search'}{'default'} = [1];

$feature{'grep'}{'default'} = [1];
$feature{'grep'}{'override'} = 1;

$feature{'show-sizes'}{'default'} = [1];
$feature{'show-sizes'}{'override'} = 1;

$feature{'avatar'}{'default'} = ['gravatar'];
$feature{'avatar'}{'override'} = 1;

$feature{'highlight'}{'default'} = [1];
$feature{'highlight'}{'override'} = 1;

终于在我的 apache 上创建了一个新的 vhost 条目

<VirtualHost 88.198.64.228:80>
        ServerName git.aranox.de
        ServerAlias www.git.aranox.de
        DocumentRoot /usr/share/gitweb
        ErrorLog /var/log/vhosts/git.aranox.de_error_log
        CustomLog /var/log/vhosts/git.aranox.de_access_log combined
        <Directory /usr/share/gitweb>
                Options +Indexes +ExecCGI +FollowSymLinks
                AllowOverride All
                Order allow,deny
                Allow from all
                AddHandler cgi-script .cgi
                DirectoryIndex gitweb.cgi
                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^.* /index.cgi/$0 [L,PT]
        </Directory>
</VirtualHost>

我重新启动了 apache2 并且看起来不错,但仍然出现“未找到项目”错误。我使用谷歌并在stackoverflow上搜索,但仍然没有找到解决方案。我一直发现权限是错误的,但我可能会这样。

感谢您的任何解决方案。

【问题讨论】:

    标签: gitolite


    【解决方案1】:

    正如OP Zack 所提到的,gitolite 将使用project.list 文件(gitweb 也使用)来了解要解析的项目列表。

    我的projects.list 是空的。不知道为什么。
    我手动添加了存储库,一切正常。

    这类似于这个问题“Gitweb document root with gitolite”,添加project.list 也足够了。


    原答案:

    这里没有直接调用gitolite,gitolite.rc文件是g2(gitolite V2)文件,不是g3 one

    首先,请确保安装最新的 gitolite V3(请参阅此installation script for instance)。

    其次,此设置不需要 git-daemon:只需要一个调用 gitweb.cgi 脚本的 Apache 服务器:参见 this httpd.conf config file,摘录如下:

    # GitWeb on @PORT_HTTP_GITWEB@
    Listen @PORT_HTTP_GITWEB@
    <VirtualHost @FQN@:@PORT_HTTP_GITWEB@>
    ServerName @FQN@
    ServerAlias @HOSTNAME@
    SetEnv GIT_HTTP_BACKEND "@H@/usr/local/apps/git/libexec/git-core/git-http-backend"
    DocumentRoot @H@/gitweb
    Alias /git @H@/gitweb
    
    <Directory @H@/gitweb>
      AddHandler cgi-script cgi
      DirectoryIndex gitweb.cgi
    

    gitweb 和 gitolite 之间的链接是通过 gitweb 钩子建立的:如果 gitweb 检测到存在 gitweb_config.perl(如 this one),就在其他 gitweb 文件中,它会调用它。反过来,我让它调用一个 gitweb.conf.pl file 并在其中调用一个名为 export_auth_hook 的函数,这是一个由 gitweb 调用的钩子(同样,如果它存在的话)。

    $export_auth_hook = sub {
      my $repo = shift;
      my $user = $ENV{GL_USER};
      # 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 $ret = &access( $repo, $user, 'R', 'any' );
      my $res = $ret !~ /DENIED/;
      return ($ret !~ /DENIED/);
    };
    

    就是这样:根据 gitolite 配置,您的 gitweb 足以显示您有权访问的项目。
    然而,这不是克隆/推送或拉取 git repo 的方法,正如我在“Missing repos in gitweb”中解释的那样。

    【讨论】:

    • 我使用 apt 安装了 gito-lite,所以我猜它是最新版本,不是吗?在哪里创建 gitweb.conf.pl 文件?我不明白为什么需要这样做,我在 /etc/gitweb.conf 路径中设置了我的存储库和我的 projects_list,可以访问 apache 的文件夹和文件。知道需要返回我的存储库名称的脚本吗? wtf
    • 您可能有另一种方法:stackoverflow.com/a/10810347/6309。但我更喜欢在现有的gitweb.conf 旁边添加我自己的gitweb.conf.pl。确保在 gitolite.conf 文件中声明您想要查看的存储库:sitaramc.github.com/gitolite/external.html
    • @Zack:很遗憾听到这个消息。我会监控这个问题,希望您在弄清楚具体情况下的问题后发布解决方案。
    • 找到了解决方案。我的 projects.list 是空的。不知道为什么。我添加了存储库手册,一切都很好。
    • @Zack 太棒了!我已经编辑了我的答案以使其更加明显。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 2017-10-08
    • 1970-01-01
    相关资源
    最近更新 更多