git push 到 nginx+git-http-backend : 错误: 无法访问 URL http 返回代码 22 致命: git-http-push 失败

4

我正在配置我的git仓库在Ubuntu 14.04上通过http服务访问(使用nginx/1.4.6+git-http-backend+fastcgi:fcgiwrap 1.1.0-2)。但是遇到了以下错误。

# git push origin master
Username for 'http://server.com': git
Password for 'http://git@gittest.cloudthis.com': 
error: Cannot access URL http://server.com/rahul.git/, return code 22
fatal: git-http-push failed

我的Nginx网站配置如下。
server {

    listen          80;
    server_name     server.com;
    root            /var/www/git/repos;

include /etc/nginx/fcgiwrap.conf; # Added as a support for cgi

auth_basic          "Welcome to my GIT repos";  # Added for Basic Auth +1
auth_basic_user_file    /etc/apache2/.htpasswd;

    location ~ /git(/.*) {
#    location /repos/ {

#client_max_body_size                   0;
        include /etc/nginx/fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
        fastcgi_param   GIT_HTTP_EXPORT_ALL     true;
        fastcgi_param   GIT_PROJECT_ROOT        /var/www/git/repos;
        fastcgi_param   PATH_INFO               $uri;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param   REMOTE_USER             $remote_user;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }
}

我将我的存储库根目录设置为/var/www/git/repos。在其中,我使用命令git --bare init firstrepo.git初始化了我的裸库,例如/var/www/git/repos/firstrepo.git/
Git clone工作正常,但是当我进行更改并执行git push origin master时,会出现错误。
# touch newfile
# git add newfile
# git commit -m " commited "
[master 059714a]  commited
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 newfile
# git push origin master
Username for 'http://server.com': git
Password for 'http://git@server.com': 
error: Cannot access URL http://server.com/rahul.git/, return code 22
fatal: git-http-push failed

有人知道我做错了什么吗?我也尝试按照这里所说的编辑.git/config文件,但是没有帮助。错误仍然存在。

在我的access.log中:

114.143.99.83 - - [14/Aug/2014:15:49:33 +0000] "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1" 401 203 "-" "git/1.9.1"
114.143.99.83 - - [14/Aug/2014:15:49:36 +0000] "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1" 401 203 "-" "git/1.9.1"
114.143.99.83 - git [14/Aug/2014:15:49:36 +0000] "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1" 200 59 "-" "git/1.9.1"
114.143.99.83 - git [14/Aug/2014:15:49:36 +0000] "GET /rahul.git/HEAD HTTP/1.1" 200 23 "-" "git/1.9.1"
114.143.99.83 - - [14/Aug/2014:15:49:37 +0000] "PROPFIND /rahul.git/ HTTP/1.1" 401 203 "-" "git/1.9.1"

在我的错误日志中

2014/08/14 15:49:33 [error] 2872#0: *19 no user/password was provided for basic authentication, client: 114.143.99.83, server: server.com, request: "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1", host: "server.com"
2014/08/14 15:49:36 [error] 2872#0: *20 no user/password was provided for basic authentication, client: 114.143.99.83, server: server.com, request: "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1", host: "server.com"
2014/08/14 15:49:37 [error] 2872#0: *21 no user/password was provided for basic authentication, client: 114.143.99.83, server: server.com, request: "PROPFIND /rahul.git/ HTTP/1.1", host: "server.com"
2个回答

3

正如Marcs所描述的那样,您可以通过启用receivepack选项来解决身份验证问题,但这会禁用身份验证要求。您实际想要的是向git-http-backend通报成功验证的用户。这可以通过将REMOTE_USER FastCGI参数设置为$remote_user Nginx变量来实现。

server {
    ...
    location ... {
        auth_basic "Restricted";
        auth_basic_user_file /path/to/.htpasswd;
        fastcgi_param REMOTE_USER $remote_user;
        ...
    }
}

考虑到您当前的Nginx配置,您可能也会遇到一个问题,即与fcgiwrap的连接过早关闭,这与 FastCGI参数的顺序问题有关。如果/etc/nginx/fastcgi_params包含例如SCRIPT_FILENAME的定义,在使用fcgiwrap时它将不会被/usr/lib/git-core/git-http-backend覆盖。


https://www.git-scm.com/docs/git-http-backend讨论了 Git 服务 receive-pack - Derek Mahar
你是否知道nginx需要哪些特定命令才能允许匿名读取访问,但需要身份验证的写入访问? - Derek Mahar
我要试一下,点个赞。 - Marcs

2

我有一个和你类似的设置。

我认为问题与receivepack选项有关。

你应该将此选项添加到裸仓库的配置文件中。

[http]
    receivepack = true

如果需要设置全局配置(就像我所做的那样),请将上面的行插入到:/etc/gitconfig

您还可以像这样使用config命令来启用存储库:

git config --local http.receivepack true

或者进行系统范围的操作:

git config --system http.receivepack true

与nginx相关的是,您还可以在位置块中使用身份验证,而不是服务器,这会使配置更加清晰(依我之见)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接