如何使用 Nginx + git-http-backend + fcgiwrap (Debian Squeeze)

bra*_*zer 5 debian nginx git

我正在尝试使用 Nginx 设置 git-http-backend,但是在浪费了 24 小时的时间并阅读了我所能阅读的所有内容之后,我认为这个配置应该可以工作,但没有。


server {
   listen   80;
   server_name  mydevserver;
   access_log /var/log/nginx/dev.access.log;
   error_log /var/log/nginx/dev.error.log;

location / {
   root  /var/repos;
}

location ~ /git(/.*) {
   gzip off;
   root /usr/lib/git-core;

   fastcgi_pass  unix:/var/run/fcgiwrap.socket;
   include /etc/nginx/fastcgi_params2;

   fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
   fastcgi_param DOCUMENT_ROOT /usr/lib/git-core/;
   fastcgi_param SCRIPT_NAME git-http-backend;

   fastcgi_param GIT_HTTP_EXPORT_ALL "";
   fastcgi_param GIT_PROJECT_ROOT /var/repos;
   fastcgi_param PATH_INFO $1;
   #fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
}
}
Run Code Online (Sandbox Code Playgroud)

/etc/nginx/fastcgi_params2 的内容


    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;

    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;

    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
    fastcgi_param  REMOTE_USER        $remote_user;

    # required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;
Run Code Online (Sandbox Code Playgroud)

但配置似乎不起作用

    $ git clone http://mydevserver/git/myprojectname/
    Cloning into myprojectname...
    warning: remote HEAD refers to nonexistent ref, unable to checkout.
Run Code Online (Sandbox Code Playgroud) 我可以请求一个不存在的项目,我会得到相同的答案
    $ git clone http://mydevserver/git/thisprojectdoesntexist/
    Cloning into thisprojectdoesntexist...
    warning: remote HEAD refers to nonexistent ref, unable to checkout.
Run Code Online (Sandbox Code Playgroud)

如果我将 root 更改为 /usr/lib 我将收到 403 错误,这将报告给 nginx 错误日志:

    2011/11/23 15:52:46 [error] 5224#0: *55 FastCGI sent in stderr: "Cannot get script
    name, is DOCUMENT_ROOT and SCRIPT_NAME set and is the script executable?" while
    reading response header from upstream, client: 198.168.0.4, server: mydevserver,
    request: "GET /git/myprojectname/info/refs HTTP/1.1", upstream:
    "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "mydevserver"
Run Code Online (Sandbox Code Playgroud)

我的主要问题是使用此配置正确的根值。也许存在一些权限问题。

笔记:

  • /var/repos/ 归 www-data 所有,包含文件夹 bit git bare repos。

  • 所有这些都可以使用 ssh 完美运行。

  • 如果我使用浏览器访问http://mydevserver/git/myproject/info/refs,它会由 git-http-backend 回答,要求我发送命令。

  • /var/run/fcgiwrap.socket 有 777 个权限。