Skip to content

Instantly share code, notes, and snippets.

@hariadi
Created August 20, 2013 23:46
Show Gist options
  • Save hariadi/6288797 to your computer and use it in GitHub Desktop.
Save hariadi/6288797 to your computer and use it in GitHub Desktop.
Apache > 2.4 Git Config
<VirtualHost *:80>
# Configure hostname
ServerAdmin postmaster@jpa.gov.my
ServerName git.jpa.gov.my
# Repository location
DocumentRoot /data/www/jpa.gov.my/git
# Deny to access
<Files ~ "(^\.htaccess|^.*\.conf)">
Require all denied
</Files>
# OPTIONAL: Completely deny pushing over HTTP
<LocationMatch "git-receive-pack">
Require all denied
</LocationMatch>
# Basic auth
# http://httpd.apache.org/docs/current/mod/mod_authz_core.html
<Location />
AuthType Basic
AuthName "Git Repositories"
AuthUserFile /path/to/htpasswd
Require valid-user
Require all granted
</Location>
# Enable cgi-bin scripts
Options ExecCGI FollowSymLinks
AddHandler cgi-script cgi
# Load configuration for Gitweb <https://git.wiki.kernel.org/index.php/Gitweb>
SetEnv GITWEB_CONFIG /etc/gitweb.conf
# Configure Git HTTP Backend
SetEnv GIT_PROJECT_ROOT /www/jpa.gov.my/git
SetEnv GIT_HTTP_EXPORT_ALL
# Note: Serve static files directly
AliasMatch ^/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1
AliasMatch ^/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1
# Note: Serve repository objects with Git HTTP backend
ScriptAliasMatch \
"(?x)^/(.*/(HEAD | \
info/refs | \
objects/info/[^/]+ | \
git-(upload|receive)-pack))$" \
/usr/libexec/git-core/git-http-backend/$1
# Note: Serve HTML with Gitweb
ScriptAlias / gitweb/gitweb.cgi
# Turning on mod rewrite
RewriteEngine on
# Make the front page an internal rewrite to the gitweb script
RewriteRule ^/$ /gitweb/gitweb.cgi [L]
# Make shortcut for a repostitory, so URL like <http://git.jpa.gov.my/my_repository.git>
# loads proper repository in Gitweb
RewriteRule ^/(\w+\.git)$ /?p=$1 [L,P]
# Configure location logs
CustomLog /var/log/apache2/git.jpa.gov.my-access.log multi
ErrorLog /var/log/apache2/git.jpa.gov.my-error.log
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment