Friday, January 19, 2018

Apache 2.4 and git

A while ago, I configured git on my server.  It seemed everything I found was on how to configure Apache 2.2 and git.  I couldn't find very much to configure it with Apache 2.4.

Here is the final configuration.  If I access using a web browser, I can navigate the repository.  If I access using git, then that works too.  Finally, it uses the system's users and passwords for authentication. 

Access is through: https://domain/git

SetEnv GIT_PROJECT_ROOT /var/lib/git
SetEnv GIT_HTTP_EXPORT_ALL

ScriptAliasMatch \
 "(?x)^/git/(.*/(HEAD | \
   info/refs | \
   objects/(info/[^/]+ | \
     [0-9a-f]{2}/[0-9a-f]{38} | \
     pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
   git-(upload|receive)-pack))$" \
 /usr/libexec/git-core/git-http-backend/$1     
Alias /git /var/www/git


<LocationMatch "^/git/">
    SetEnvIfExpr "%{QUERY_STRING} =~ /git-receive-pack/" AUTHREQUIRED=yes
    SetEnvIf Request_URI "/git-receive-pack$" AUTHREQUIRED=yes

    AuthType Basic
    AuthName "Git Access"
    AuthBasicProvider external
    AuthExternal pwauth
    <RequireAny>
       <RequireAll>
          Require env AUTHREQUIRED
          require valid-user
       </RequireAll>
       <RequireAll>
          Require not env AUTHREQUIRED
          Require all granted
       </RequireAll>
    </RequireAny>
</LocationMatch>

<Directory /var/www/git>
  Options +ExecCGI
  AddHandler cgi-script .cgi
  DirectoryIndex gitweb.cgi
  SSLRequireSSL

  # Enable mod_rewrite 
  # RewriteEngine on 
  # Rewrite /git/repo.git URIs to be /git/gitweb.cgi/repo.git 
  # This assumes your repository names end with '.git'. I don't 
  # know if that is always a safe assumption. 
  # RewriteRule ^([^.]+\.git.*)$ /git/gitweb.cgi/$0 [L,PT]
</Directory>

No comments:

Post a Comment