首页 > 解决方案 > NGINX fastcgi 代理上使用 git-http-backend 的多个同时请求

问题描述

git-http-backend通过 nginx fastcgi 代理服务 git repos。nginx 配置如下所示:

server {
    listen               443 ssl;
    server_name          git.example.com;

    auth_basic           "Git Access";
    auth_basic_user_file /etc/nginx/.htpasswd_git;
    error_log            /var/log/nginx-git-error.log;
    access_log           /var/log/nginx-git-access.log;
    client_max_body_size 0;

    root /var/git/;

    location ~ /git(/.*) {

        fastcgi_pass  unix:/var/run/fcgiwrap.socket;
        include       fastcgi_params;
        fastcgi_param SCRIPT_FILENAME     /usr/lib/git-core/git-http-backend;
        fastcgi_param GIT_PROJECT_ROOT    /var/git;
        fastcgi_param REMOTE_USER         $remote_user;
        fastcgi_param PATH_INFO           $1;
        fastcgi_read_timeout              600;
    }
}

从测试来看,如果一次有多个请求,代理将失败(代码为 504),并且一些谷歌搜索似乎证实了我的怀疑,即git-http-backend不能支持多个请求。

如何设置它以便可以一次向 git repo 发出多个请求?

标签: gitnginxwebserverfastcgi

解决方案


我最近也遇到了同样的情况,很快在github上找到了这个脚本

它为每个新的 http 请求生成一个新的 git-http-backend 实例。编译它(需要安装go语言)通过

go build git-http-multi-backend.go

并运行它

./git-http-multi-backend -r /Path/To/Repos

这将使它在 :80 上侦听(可以更改端口)。您现在只需将您的 nginx 配置更改为类似

location ~ /git(/.*) {
    proxy_pass http://localhost:80;
}

我承认,这不是最优雅的解决方案,因为完全可以通过摆弄 nginx 配置来实现相同的效果。git-http-multi-backend 工具的作者甚至谈到了它,但缺乏任何具体的实现示例。


推荐阅读