Created
July 21, 2010 07:43
-
-
Save karmi/484199 to your computer and use it in GitHub Desktop.
Configuration for hosting Git repositories with Apache 2.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------------------------------------- | |
# Configuration for hosting Git repositories with Apache 2.x | |
# ---------------------------------------------------------- | |
# | |
# This setup provides "dual URLS", where URL like <http://git.example.com/my_repository.git> | |
# loads Gitweb in the browser and the same URL can be used in commands like `git clone` and `git remote add`. | |
# It was compiled from some sources on the internet and further customized/tuned. | |
# | |
# Please see documentation for: | |
# | |
# 1. `git-http-backend`, <http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html> | |
# 2. `gitweb`, <http://repo.or.cz/w/alt-git.git?a=blob_plain;f=gitweb/README> | |
# | |
# Also see Scott Chacon's "Smart HTTP Transport", <http://progit.org/2010/03/04/smart-http.html> | |
<VirtualHost *:80> | |
# Configure hostname | |
ServerAdmin [email protected] | |
ServerName git.example.com | |
# Configure repository location | |
DocumentRoot /data/www/example.com/git | |
# Deny to access to .htaccess etc | |
<Files ~ "(^\.htaccess|^.*\.conf)"> | |
Order allow,deny | |
Deny from all | |
</Files> | |
# OPTIONAL: Completely deny pushing over HTTP | |
<LocationMatch "git-receive-pack"> | |
Order Allow,Deny | |
Deny from all | |
</LocationMatch> | |
# OPTIONAL: Require authentication for access | |
# See http://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html | |
<Location /> | |
AuthType Basic | |
AuthName "Git Repositories" | |
AuthUserFile /path/to/file # For `htpasswd` command | |
Require valid-user | |
Order allow,deny | |
Allow from all | |
</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/example.com/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.example.com/my_repository.git> | |
# loads proper repository in Gitweb | |
RewriteRule ^/(\w+\.git)$ /?p=$1 [L,P] | |
# Configure location logs | |
CustomLog /var/log/apache2/git.example.com-access.log multi | |
ErrorLog /var/log/apache2/git.example.com-error.log | |
</VirtualHost> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment