You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx配置Git智能HTTP服务遇fatal: repository not found错误求助

问题排查与解决方案

根据你提供的错误日志和配置,核心问题是git-http-backend无法识别指定路径为有效的Git仓库,以下是针对性的排查步骤和修复方案:

1. 验证仓库有效性

首先确认仓库本身是有效的Git裸仓库(托管仓库必须是裸仓库,非裸仓库无法通过智能HTTP正常提供服务):

cd /home/path/to/repositories/repo-name.git
git rev-parse --is-bare-repository
  • 如果返回true,说明仓库格式正确;
  • 如果返回false或报错,需重新创建裸仓库:
# 先备份原仓库(如果需要)
mv /home/path/to/repositories/repo-name.git /home/path/to/repositories/repo-name.git.bak
# 创建新的裸仓库
git init --bare /home/path/to/repositories/repo-name.git

2. 修复Nginx配置中的PATH_INFO参数

当前配置里的PATH_INFO使用$uri会包含开头的斜杠,导致git-http-backend拼接路径时可能出现异常。修改location规则和PATH_INFO配置:

server {
    listen 80; # 修正原配置里的listen80;为listen 80;
    root  /home/path/to/repositories;
 
    location ~ ^/(.+\.git)/ { # 捕获仓库路径部分
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/.gitpasswd;
        
        include fastcgi_params; 
        fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
        fastcgi_param GIT_PROJECT_ROOT /home/path/to/repositories;
        fastcgi_param GIT_HTTP_EXPORT_ALL "";
        fastcgi_param PATH_INFO /$1; # 传递正确的相对路径
        fastcgi_param REMOTE_USER $remote_user;
        client_max_body_size 0;

        fastcgi_pass unix:/var/run/fcgiwrap.socket; 
    }
}

3. 检查文件权限

确保fcgiwrap运行的用户(通常是www-data)对仓库目录拥有读取权限,以及父目录的执行权限:

# 赋予www-data用户仓库目录的所有权
chown -R www-data:www-data /home/path/to/repositories
# 设置合理的目录权限
chmod -R 755 /home/path/to/repositories

4. 重启服务验证

修改配置后重启Nginx和fcgiwrap服务:

systemctl restart nginx
systemctl restart fcgiwrap

然后重新执行克隆命令测试:

git clone http://user:password@my-local-ip/repo-name.git folder-name

内容的提问来源于stack exchange,提问作者enriquesb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 20:35:16