如何使用 nginx 通过 HTTP 发布 git repo?

Cha*_*raf 8 centos git nginx

我在 domain.fr 上有一台 CentOS 5 服务器。我正在尝试设置一个子域,以便我可以将它与 git 一起使用: git.domain.fr

我的存储库在 /home/git (例如 /home/git/repos.git)

我已经安装了git-http-backendNginx。我已经设置了这样的存储库:

cd /home/git/repos.git && git --bare init
Run Code Online (Sandbox Code Playgroud)

我已将我的git.conf(包含在 中nginx.conf)设置为如下。

但是,在我的客户端 shell 上,我收到致命错误“找不到存储库”: git clone http://git.domain.fr/repos.git

有谁知道我应该做什么?看起来很简单,我很沮丧,因为我确定这没什么。

server {

    listen          80;
    server_name     git.domain.fr;
    root            /home/git;

    location ~ /(/.*) {

        include /etc/nginx/fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME /usr/bin/git-http-backend;
        fastcgi_param   GIT_HTTP_EXPORT_ALL     true;
        fastcgi_param   GIT_PROJECT_ROOT        /home/git;
        fastcgi_param   PATH_INFO               $1;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }
}
Run Code Online (Sandbox Code Playgroud)

slm*_*slm 3

我在一个标题为: How to service GIT via HTTP via NGINX with user/password? 的SO Q&A 中找到了这个片段。。

http {
    ...
    server {
        listen       80;
        server_name  git.mydomain.com;

        location ~ /git(/.*) {
            # fcgiwrap is set up to listen on this host:port
            fastcgi_pass  localhost:9001;
            include       fastcgi_params;
            fastcgi_param SCRIPT_FILENAME     /usr/lib/git-core/git-http-backend;
            # export all repositories under GIT_PROJECT_ROOT
            fastcgi_param GIT_HTTP_EXPORT_ALL "";
            fastcgi_param GIT_PROJECT_ROOT    /srv/git;
            fastcgi_param PATH_INFO           $1;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我会确保你的设置尽可能地反映这一点。另外,由于我相信 Apache 正在访问您的/home/git目录,因此您需要注意该用户是否能够这样做。此外,如果您使用 SELinux,您需要确保进程 (httpd) 添加了适当的上下文,/home以便它也能够访问此目录。

请查阅您的/var/log/httpd/error_log日志文件以获取有关 Apache 出错位置的更多详细信息。