git.ithinksw.org is a pretty nifty site: in addition to providing Gitweb when you access it via a web browser, it also allows cloning of repositories in the same namespace. So, for example, you can visit http://git.ithinksw.org/ITFoundation.git, and receive a Gitweb-generated interface to the repository, but you can also run git clone http://git.ithinksw.org/ITFoundation.git to clone the repository. tycho is also a fan of Git, and was interested in setting a similar site up for his own repositories, so I've decided to share my configuration here.
My servers tend to run Debian GNU/Linux, because I am totally in love with dpkg and APT. I generally like being able to rely on automatic updates to my software, and Gitweb should be no exception, so this configuration uses the copy of Gitweb that is maintained by dpkg.
git.ithinksw.org also runs git-daemon to support the git:// protocol. One of the features of git-daemon is support for per-user public_git directories. Of course, Apache has the mod_userdir module to provide a similar feature over HTTP. With a little mod_rewrite hackery, the git:// and http:// clone URLs for every repository are identical, and every repository has a Gitweb interface.
This configuration relies on two things:
Here is an example of the layout of the server's filesystem (paths followed by lines that begin with -> are symbolic links to the following path):
/home/user/public_git/repository.git
/srv/git/git.ithinksw.org/ITFoundation.git
/srv/www/git.ithinksw.org/gitweb/gitweb.conf
/srv/www/git.ithinksw.org/gitweb/root/ITFoundation.git
-> /srv/git/git.ithinksw.org/ITFoundation.git
/srv/www/git.ithinksw.org/gitweb/root/\~user
-> /home/user/public_git
Here is the relevant gitweb.conf:
$projectroot = "/srv/www/git.ithinksw.org/gitweb/root";
$git_temp = "/tmp";
$home_text = "indextext.html";
$projects_list = $projectroot;
$stylesheet = "/gitweb.css";
$logo = "/git-logo.png";
$favicon = "/git-favicon.png";
@git_base_url_list = qw(git://git.ithinksw.org http://git.ithinksw.org);
$site_name = "git.ithinksw.org";
$home_link_str = "git.ithinksw.org";
$projects_list_description_width = "200";
$feature{'pathinfo'}{'default'} = [1];
Here is the VirtualHost configuration for Apache:
DocumentRoot /srv/git/git.ithinksw.org
UserDir public_git
UserDir enabled
# gitweb
SetEnv GITWEB_CONFIG /srv/www/git.ithinksw.org/gitweb/gitweb.conf
Alias /gitweb.css /usr/share/gitweb/gitweb.css
Alias /git-logo.png /usr/share/gitweb/git-logo.png
Alias /git-favicon.png /usr/share/gitweb/git-favicon.png
ScriptAlias /gitweb /usr/lib/cgi-bin/gitweb.cgi
RewriteEngine on
# redirect userdir listing to gitweb search
RewriteRule ^/?(~[^/]+)/?$ /?s=$1 [R]
# rewrite all other paths that aren't git repo internals to gitweb
RewriteRule ^/$ /gitweb [PT]
RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /gitweb%{REQUEST_URI} [L,PT]
That's all there is to it! I do hope that you'll read the documentation for the tools I've employed here, so that you may fully understand what is going on. This will give you a very basic setup similar to the one at git.ithinksw.org, but you'll need to know what's going on to further customize or improve on what I've provided. Good luck, and do let me know if you improve on these beginnings or have any suggestions!