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

前端 未结 3 966
余生分开走
余生分开走 2020-12-02 13:44

Despite all the links I\'ve found on how to configure git/nginx to get my repos, I can\'t make them work.

I followed this tutorial, Git repository over HTTP WebDAV w

3条回答
  •  有刺的猬
    2020-12-02 14:36

    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?

提交回复
热议问题