nginx + cgit in a subfolder

I’ve recently decided to give nginx a try. So far I’ve used Apache httpd 2.4 exclusively, but I wanted to get to know the competitor prior to sticking with Apache httpd or switching to nginx depending on the result. There are lots of claims about nginx’s performance and Apache httpd’s bloat, but I simply wanted to get started with a test scenario. For me this scenario was running the cgit web interface on http://localhost/cgit/. Next to the configuration files the only major difference to me is: nginx only provides a FastCGI interface, while I was using the built-in CGI interface in Apache. Luckily FastCGI is not hard to set up nowadays. On ArchLinux it basically boils down to the following three commands:

pacman -S nginx fcgiwrap
systemctl enable fcgiwrap.socket
systemctl start fcgiwrap.socket

After this you can use FastCGI, and thanks to systemd it is socket activated, i.e. it is only started when someone is accessing it. Afterwards I reused my /etc/cgitrc from the previous Apache httpd, which looks more or less like this:

root-title=My git Server
root-desc=This is my very own git server!


section=Some section

repo.url=Some Repo

For me the largest obstacle was setting „virtual-root = /cgit“, which was not necessary for Apache httpd, but mandatory for nginx. This has to match the property set in /etc/nginx/nginx.conf

http {
 server {
   location /cgit {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi;
    fastcgi_pass unix:/run/fcgiwrap.sock;
    fastcgi_split_path_info           ^(/cgit/?)(.+)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param QUERY_STRING $args;
   location /cgit-web {
    rewrite ^/cgit-web(/.*)$ $1 break;
    root /usr/share/webapps/cgit;

After performing this small amount of configuration in nginx the server was up and running. In my very own and non-representative test scenario nginx and Apache httpd performed very similar (tested using jmeter). Even the memory usage was not that different. So at least for me the difference was not enough to convince me to permanently change my setup for now. Most of the things I need (PHP, ~/public_html, cgit) work fine on both, and my Apache httpd configuration is solid and proven for years.

If you have other suggestions on why to use nginx over Apache httpd feel free to inform me about it.

Copyright ©, 2002-2017.