Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to setup git-http-backend with Nginx but after 24 hours wasting time and reading everything I could I think this config should work but doesn't.


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;
}
}

Content of /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;

but config seems not working

    $ git clone http://mydevserver/git/myprojectname/
    Cloning into myprojectname...
    warning: remote HEAD refers to nonexistent ref, unable to checkout.
and I can request an unexistant project and I will get the same answer
    $ git clone http://mydevserver/git/thisprojectdoesntexist/
    Cloning into thisprojectdoesntexist...
    warning: remote HEAD refers to nonexistent ref, unable to checkout.

If I change root to /usr/lib I will get a 403 error and this will be reported to nginx error log:

    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"

My main trouble is with the correct root value with this configuration. Maybe there are some permissions problems.

Notes:

  • /var/repos/ is owned by www-data and contains folders bit git bare repos.

  • All this works perfectly using ssh.

  • If I go with my browser to http://mydevserver/git/myproject/info/refs it is answered by git-http-backend asking me to send a command.

  • /var/run/fcgiwrap.socket has 777 permissions.

share|improve this question
    
Considering moving from svn to git (with nginx) but bumped with this one. I really want the avoid apache. Have you tried this [nrfw.org/git_server_setup.html]? –  ruionwriting Dec 26 '11 at 23:52

4 Answers 4

move down fastcgi_pass ; it should be the latest line.

First you should set parameters, only then fastcgi_pass, otherwise you will not get set environment.

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

share|improve this answer

I found this article and have done it successfully. http://blog.publicfields.net/2011/03/how-to-setup-your-very-own-git-server.html.

See section 3. Web-interface: nginx and cgit.

You can try it. good luck

share|improve this answer
    
Please include the relevant sections from the article. –  Lucas Kauffman Apr 1 '12 at 17:34

Try to change the order between the two lines in your config file:

include /etc/nginx/fastcgi_params2;

fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
share|improve this answer

This is probably a bug with the version of fcgiwrap found on debian squeeze (1.0-1+squeeze1). See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=698071

Upgrading to fcgiwrap 1.0.3-3 (found in debian testing) solved the issue for me. Here is the config I used (note I did not need to define "root"):

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

    location ~ /git(/.*) {
        gzip off;
        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 GIT_HTTP_EXPORT_ALL "";
        fastcgi_param GIT_PROJECT_ROOT /var/repos;
        fastcgi_param PATH_INFO $1;
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.