Ubuntu 服务器中使用 GitWeb。

sudo apt install highlight fcgiwrap git

Nginx 配置

使用本配置时克隆地址为 https://git.example.com/clone/project

server {
    server_name git.example.com;

    location ~ /clone(/.*) {
        client_max_body_size 0;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
        fastcgi_param GIT_PROJECT_ROOT /srv/git;
        fastcgi_param PATH_INFO $1;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }

    location /gitweb.cgi {
        root /usr/share/gitweb;
        gzip off;
        include fastcgi_params;
        fastcgi_param SCRIPT_NAME $uri;
        fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }
    location / {
        root /usr/share/gitweb;
        index gitweb.cgi;
    }
}

配置

配置文件为 /etc/gitweb.conf

Git 仓库存于 /srv/git/projects

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

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

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

# 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 = ();

# 不显示 owner
$omit_owner = 1;

# 只显示 bare repo 中有 "git-daemon-export-ok" 这个文件的仓库
$export_ok = "git-daemon-export-ok";

# 语法高亮(需要 highlight 包)
$feature{'highlight'}{'default'} = [1];

/srv/git/indextext.html 中写入需要在主页中额外添加的文字。

echo 'My personal git repos' | sudo tee /srv/git/indextext.html

外部链接