cgit with Nginx/uWSGI in a Subfolder

Posted on Sun 15 November 2015

I recently upgraded some VMs from Debian Wheezy to Jessie (actually I did clean reinstalls), which finally made a package for cgit available.

So I took the opportunity to switch the hosted git web frontends from some crappy (possibly insecure) PHP stuff to cgit, integrated into my Nginx setup via uWSGI.

Now if you want your cgit interface to reside under a "subfolder", i.e. one or more levels below your web root, then you run into problems as the PATH_INFO environment extracted from the request URL contains the subfolder component(s). This confuses cgit which is not designed to be used in subfolders.

Crawling the web you find lots of references to Nginx config snippets like this

uwsgi_param SCRIPT_NAME /cgit;
uwsgi_modifier1 30;

but unfortunately that modifier seems to have been dropped (it has been deprecated for long time).

In order to work around this I make use of fastcgi_split_path_info:

    location /cgit {
        gzip off;

        include uwsgi_params;
        uwsgi_pass unix:/var/run/uwsgi/app/cgit/socket;
        uwsgi_modifier1 9;

        fastcgi_split_path_info ^(/cgit/?)(.+)$;
        uwsgi_param PATH_INFO $fastcgi_path_info;

tags: cgit, nginx, uwsgi, webserver, git | category: howto