How to: Gitorious and Sendfile for tarball download with Nginx

On Apache Gitorious uses mod_xsendfile to push the tarballs for download. Unfortunately this is not directly compatible with Nginx because Nginx uses a similar but different implementation.

However the is still a way to make this feature work with Nginx. To do so you first have to edit on of the gitorious controllers to. Assuming that gitorious is installed in /var/www/gitorious/ you have to edit the following file

sudo nano /var/www/gitorious/app/controllers/trees_controller.rb

Once you open the file search for the line

response.headers["X-Sendfile"] = File.join(GitoriousConfig["archive_cache_dir"], real_path)

It is in the function:

set_xsendfile_headers(real_path, user_path, content_type = "application/x-gzip")

and replace with the following:

response.headers["X-Accel-Redirect"] = GitoriousConfig["nginx_sendfile_dir"] + real_path

Save the file and open the gitorious configuration file for editing.

sudo nano /var/www/gitorious/config/gitorious.yml

There you have to add the following line (am not sure the position of the line in the configuration is relevant but you can add the line after the default license line):

nginx_sendfile_dir: "/cache/"

Finally in the nginx virtual host for your gitorious instance you have to add the following line (the alias has to be the archive_cache_dir: from gitorious.yml, let’s suppose you set it to /var/git/tarballs)

location /cache {
alias /var/git/tarballs;