Build a gitweb server on Ubuntu

1.install nginx gitweb spawn-fcgi fcgiwrap

$ sudo apt-get install spawn-fcgi fcgiwrap nginx git-core

2. nginx config

Add a config file /etc/nginx/sites-enabled/gitweb

server {
    listen 8086;
    server_name "Git Server";
 
   location /gitweb {
        root /usr/share;
    
        index index.cgi;
        include fastcgi_params;
        gzip off;
        fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; ##相关配置见“配置gitweb”

        if ($uri ~ "/index.cgi") {
                fastcgi_pass unix:/var/run/fcgiwrap.socket;
        }
    }
}

配置通过http下载 git代码

# 配置以 /git 开始的虚拟目录
location ~ /git(/.*) {
    # 使用 Basic 认证
    #auth_basic "Restricted";
    # 认证的用户文件
    #auth_basic_user_file /etc/nginx/passwd;
    # FastCGI 参数
    fastcgi_pass  unix:/var/run/fcgiwrap.socket;
    fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
    fastcgi_param GIT_HTTP_EXPORT_ALL "";
    # git 库在服务器上的跟目录
    fastcgi_param GIT_PROJECT_ROOT    /var/git-repos;
    fastcgi_param PATH_INFO           $1;
    # 将认证用户信息传递给 fastcgi 程序
    fastcgi_param REMOTE_USER $remote_user;
    # 包涵默认的 fastcgi 参数;
    include       fastcgi_params;
    # 将允许客户端 post 的最大值调整为 100 兆
    #max_client_body_size 100M;
}

3. gitweb config

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

# 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 = $projectroot;

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

##########

4.start

$ sudo /etc/init.d/fcgiwrap start
$ sudo nginx -s reload

5. 其他

a)下载大文件报错

error: RPC failed; HTTP 504 curl 22 The requested URL returned error: 504 Gateway Time-out
fatal: The remote end hung up unexpectedly

解决办法:
增加fcgi读写等待时间

fastcgi_read_timeout 1000;
fastcgi_read_timeout 1000;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容