Publish GitWeb with Nginx Reverse-Proxying for Apache

Most installation guides for GitWeb assume that it will be hosted by a single web-server process (either Nginx or Apache). This article will show how to host GitWeb with Nginx acting as a front-end for Apache.

Assumptions

  • The Server OS is Debian/Lenny “stable”
  • Nginx is setup to listen for incoming connections on a publicly-accessible IP
  • Apache is configured to allow for multiple virtual hosts on the localhost IP

Nginx Compatability

For GitWeb to work correctly, the installed version of Nginx must support the try_files directive. Unfortuantely, the Debian “stable” version of Nginx (0.6.xx) does not. Hence, the Nginx install will need to be upgraded to 0.7.27 or higher. In Debian/Lenny, this can be easily accomplished with Backports – refer the Backports FAQ on adding backports to your sources.list file. Once that is done, the only command required is:

Nginx Configuration

Add the following to your website configuration file under /etc/nginx/sites-available:

Explaining the Nginx Configuration

Some of the core parameters that affect the setup are explained below:

ParamterExplanation
server_name gitweb.domain.com;The rest of the configuration assumes GitWeb is being served from a subdomain. If Gitweb is being hosted at domain.com/gitweb, then the ”/” and ”@gitweb” location directives will need to be modified accordingly
This instructs Nginx to try and serve the requested resource from the path specified in the root directive, or else transfer processing to the “gitweb” location

Apache Configuration

Add The following to the site configuration file in /etc/apache2/sites-available:

Explaining the Apache Configuration

Much of the configuration here is directly from the GitWeb README. The only additional directives here pertains to gzip compression of the output, i.e.:

ParamterExplanation
The default mime.types file that Apache uses does not recognize cgi files. This adds a handle for the cgi files and activates gzip compression (all settings defaulted) for the output

Testing the configuration

Reload Nginx and Apache and then navigate to gitweb.domain.com. The familiar GitWeb page should come up.