Gitweb with nginx on Ubuntu

Gitweb is a way to view git repositories in web browser.gitweb can be configured with nginx web server.

This was tested on Ubuntu 12.04.2 LTS.

Install gitweb(Assuming git repositories are already in place)

sudo apt-get install gitweb fcgiwrap

Configure gitweb by opening /etc/gitweb.conf.modify the root path of repository.

$projectroot = "/your/repo/path";

Install nginx

sudo apt-get install nginx

Configure virtualhost for gitweb on nginx

copy default sites config

cp /etc/nginx/sites-available/default /etc/nginx/sites-available/gitweb

Open /etc/nginx/sites-available/gitweb and modify as below

server {
listen 80; ## listen for ipv4; this line is default and implied

root /usr/share/gitweb;
index index.cgi;

# Make site accessible from intranet
server_name gitweb.site.com;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.cgi;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}

location /index.cgi {
root /usr/share/gitweb/;
include fastcgi_params;
gzip off;
fastcgi_param SCRIPT_NAME $uri;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}

}

Create link

ln -s /etc/nginx/sites-available/gitweb /etc/nginx/sites-enabled/gitweb

Restart nginx

/etc/init.d/nginx restart

Now test the site by accessing the URL over browser(after adding dns/host file entries).
http://gitweb.site.com

If site is accessible and you can view the repositories, then gitweb integration with nginx is successful.If you are not able see the repositories by hitting the URL, then review the steps above again and check if you missed anything.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s