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

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))$" \
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
          Require env AUTHREQUIRED
          require valid-user
          Require not env AUTHREQUIRED
          Require all granted

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

  # 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]

No comments:

Post a Comment