git push to nginx + git-http-backend:error:无法访问URL http返回码22致命:git-http-push failed

时间:2014-08-14 16:01:13

标签: git nginx fastcgi

我正在配置我的git repos以在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;
    }
}

我的repos根目录为/var/www/git/repos。我使用命令/var/www/git/repos/firstrepo.git/

初始化了我的裸存储库,如git --bare init firstrepo.git

Git克隆工作正常,但当我进行更改并执行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文件编辑为here

,但没有帮助。错误保持不变

在我的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"

在我的error.log

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 个答案:

答案 0 :(得分:3)

作为described by Marcs,您可以通过启用receivepack选项解决身份验证问题,但disables the requirement for authentication。您更想要的是与git-http-backend通信哪个用户已成功通过身份验证。这可以通过将REMOTE_USER FastCGI参数设置为$remote_user Nginx variable来完成。

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

考虑到您当前的Nginx配置,您可能还会遇到与fcgiwrap的连接过早关闭的问题,这与order of FastCGI parameters matter有关。如果/etc/nginx/fastcgi_params包含例如SCRIPT_FILENAME的定义/usr/lib/git-core/git-http-backend,使用fcgiwrap时不会被perl覆盖。

答案 1 :(得分:2)

我得到了类似的设置。

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

您应该将此选项添加到裸存储库的配置文件

[http]
    receivepack = true

或者对于系统范围的设置(正如我所做的那样)将上面的行插入:/ etc / gitconfig

您也可以使用这样的config命令启用存储库:

  

git config --local http.receivepack true

或者在全系统范围内进行:

  

git config --system http.receivepack true

与nginx相关,您还可以在位置块中使用身份验证而不是服务器,从而使配置更加干净(IMO)。