git 安装 GitWeb - 如何

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15104736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:14:21  来源:igfitidea点击:

Installing GitWeb - How to

gitgitweb

提问by Richie

I've just installed Git on my production server and am hoping to get GitWeb working with it. I became very interested in getting it to work when I stumbled across a tutorial showing how to make git web work using...

我刚刚在我的生产服务器上安装了 Git,希望 GitWeb 能够使用它。当我偶然发现一个展示如何使用 git web 工作的教程时,我对让它工作非常感兴趣......

git instaweb -d webrick --start

git instaweb -d webrick --start

It works exactly as described in the tutorial at ... http://lostechies.com/jasonmeridth/2009/09/27/git-instaweb/

它完全按照教程中的描述工作...... http://lostechies.com/jasonmeridth/2009/09/27/git-instaweb/

However after reading other forums it seems like instaweb is not really meant to be used and instead I should set up GitWeb to run on Apache.

然而,在阅读其他论坛后,似乎 instaweb 并不是真的要使用,而是我应该设置 GitWeb 以在 Apache 上运行。

I am fairly new to Apache so am not very familiar with what I should be doing. I've been following the tutorial at http://unix-heaven.org/node/31. But i don't think I need all of it. I think the only thing I need to do is put the following in my httpd.conf file...

我对 Apache 还很陌生,所以我不太熟悉我应该做什么。我一直在关注http://unix-heaven.org/node/31 上的教程。但我不认为我需要所有这些。我认为我唯一需要做的就是将以下内容放入我的 httpd.conf 文件中...

<VirtualHost *:80>
    ServerAdmin <a href="mailto:[email protected]">[email protected]</a>
    ServerName git.example.org
    ServerAlias git-pub.example.org
    RedirectMatch ^/$ /gitweb.cgi
    SetEnv GITWEB_PROJECTROOT /cvs/codeRepository/git

    Alias /gitweb.js                /srv/www/gitweb/static/gitweb.js
    Alias /gitweb.css               /srv/www/gitweb/static/gitweb.css
    Alias /git-logo.png             /srv/www/gitweb/static/git-logo.png
    Alias /git-favicon.png           /srv/www/gitweb/static/git-favicon.png

    ScriptAlias / "/srv/www/gitweb/"

    <Directory "/srv/www/gitweb/">
        AllowOverride None
        Options Indexes FollowSymLinks ExecCGI
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog "/var/log/apache2/httpd-git-pub.example.org-access.log"
    CustomLog "/var/log/apache2/httpd-git-pub.example.org-error.log" common
</VirtualHost>

Where /srv/www/gitweb/ contains....

其中 /srv/www/gitweb/ 包含....

$:/srv/www/gitweb # ls -ltr
total 252
-rwx------ 1 root root 247917 Feb 27 15:02 gitweb.cgi
drwx------ 2 root root   4096 Feb 27 15:03 static

Will the config I've specified above work or I need to specify ? And if so what url will I access GitWeb at? Do I need serverName, serverAlias and serverAdmin?

我上面指定的配置会起作用还是我需要指定?如果是这样,我将通过哪个 URL 访问 GitWeb?我需要 serverName、serverAlias 和 serverAdmin 吗?

Thanks for your help

谢谢你的帮助

回答by VonC

The url you would use would be

您将使用的网址是

http://git.example.org

But I am not so sure about your config. Mine is simpler, and I always recommend an address like http(s)://yourServer/gitweb, instead of just http(s)://yourServer/: if you need to add more services, you can add more root url (like /gitweb).

但我不太确定你的配置。我的比较简单,我总是推荐一个像 http(s)://yourServer/gitweb 这样的地址,而不只是 http(s)://yourServer/:如果你需要添加更多的服务,你可以添加更多的 root url (喜欢/gitweb)。

For a quick http access without authentication:

对于无需身份验证的快速 http 访问:

# GitWeb on 80
Listen 80
<VirtualHost *:80>

  ServerName git.example.org
  ServerAlias git-pub.example.org

  SetEnv GITWEB_PROJECTROOT /cvs/codeRepository/git
  SetEnv GIT_HTTP_BACKEND "/usr/local/apps/git/libexec/git-core/git-http-backend"

  DocumentRoot /srv/www/gitweb
  Alias /gitweb /srv/www/gitweb

  <Directory /srv/www/gitweb>

    Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
    AllowOverride All
    order allow,deny
    Allow from all

    AddHandler cgi-script cgi
    DirectoryIndex gitweb.cgi

  </Directory>

  BrowserMatch ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

  LogLevel Info
  ErrorLog "/var/log/apache2/gitweb_error_log"
  TransferLog "/var/log/apache2/gitweb_access_log"

</VirtualHost>

Note: in my original config file(which is a template, with placeholder values like @PORT_HTTP_GITWEB@), I didn't use GITWEB_PROJECTROOTbecause I am calling Gitolite, which knows where the Git repos are.

注意:在我的原始配置文件(它是一个模板,带有像 的占位符值 @PORT_HTTP_GITWEB@)中,我没有使用,GITWEB_PROJECTROOT因为我正在调用 Gitolite,它知道 Git 存储库在哪里。

I do set a variable in the gitweb.conffile, though, which plays the same role than GITWEB_PROJECTROOT, according to the gitweb documentation:

不过,根据gitweb 文档,我确实在gitweb.conf文件中设置了一个变量,它的作用与 相同 :GITWEB_PROJECTROOT

 $projectroot::

Absolute filesystem path which will be prepended to project path; the path to repository is $projectroot/$project.
Set to $GITWEB_PROJECTROOTduring installation.
This variable has to be set correctly for gitweb to find repositories.

For example, if $projectrootis set to "/srv/git" by putting the following in gitweb config file:

将被添加到项目路径的绝对文件系统路径;存储库的路径是$projectroot/$project. 在安装过程中
设置为$GITWEB_PROJECTROOT
必须为 gitweb 正确设置此变量才能查找存储库。

例如,如果通过将以下内容放在 gitweb 配置文件中将其$projectroot设置为“ /srv/git”:

----------------------------------------------------------------------------
our $projectroot = "/srv/git";
----------------------------------------------------------------------------

then:

然后:

------------------------------------------------
http://git.example.com/gitweb.cgi?p=foo/bar.git
------------------------------------------------

and its path_info based equivalent

及其基于 path_info 的等效项

------------------------------------------------
http://git.example.com/gitweb.cgi/foo/bar.git
------------------------------------------------

will map to the path '/srv/git/foo/bar.git' on the filesystem.

将映射到文件系统上的路径“/srv/git/foo/bar.git”。



Update August 2018, for Git 2.19 (Q3 2018, five years later)

2018 年 8 月更新,适用于 Git 2.19(2018 年第三季度,五年后)

"git instaweb" has been adjusted to run better with newer Apache on RedHat based distros.

git instaweb”已经过调整,可以在基于 RedHat 的发行版上更好地与较新的 Apache 一起运行。

See commit 757b124(07 Aug 2018), and commit 1976311(08 Aug 2018) by Sebastian Kisela (skisela).
(Merged by Junio C Hamano -- gitster--in commit 93ded33, 20 Aug 2018)

提交757b124(2018年8月7日),并提交1976311(2018年8月8日),由塞巴斯蒂安Kisela( )skisela
(由Junio C gitsterHamano合并-- --在2018 年 8 月 20 日提交 93ded33 中

git-instaweb: fix apache2 config with apache >= 2.4

The generated apache2 config fails with apache >= 2.4. The error log states:

AH00136: Server MUST relinquish startup privileges before accepting connections.  
Please ensure mod_unixd or other system security module is loaded.
AH00016: Configuration Failed

Fix this by loading the unixdmodule.
This works with older httpdas well, so no IfVersionconditional is needed. (Tested with httpd-2.2.15 on CentOS-6.)

git-instaweb: 使用 apache >= 2.4 修复 apache2 配置

生成的 apache2 配置失败,apache >= 2.4。错误日志指出:

AH00136: Server MUST relinquish startup privileges before accepting connections.  
Please ensure mod_unixd or other system security module is loaded.
AH00016: Configuration Failed

通过加载unixd模块来解决这个问题
这也适用于更老的httpd,所以不需要IfVersion条件。(在 CentOS-6 上用 httpd-2.2.15 测试。)