How to serve GIT through HTTP via NGINX with user/password?

Take a look at the following article, http://www.toofishes.net/blog/git-smart-http-transport-nginx/

It provides a sample nginx config:

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

What this does is pass your repo which is located after /git in the url, to /usr/lib/git-core/git-http-backend. Example, http://git.mydomain.com/git/someapp would point to the someapp repository. This repo would be located in /srv/git/someapp as defined in the fastcgi_param of GIT_PROJECT_ROOT and can be changed to fit your server.

This is very useful and you can apply HttpAuthBasicModule to nginx to password protect your repo’s access via HTTP.

Edit: If you are missing git-http-backend, you can install the git-core package on Ubuntu/Debian or on RPM based platforms look at How can git be installed on CENTOS 5.5?

Leave a Comment