nginx and Debian-packaged CGI programs

Just in case you've wondered how to get Debian's dwww, or other CGI programs, working with the nginx httpd, the following did the trick on Debian 8 (Jessie) for me:

  • Install the fcgiwrap package

  • Add the following location snippet to /etc/sites-available/default:

      server {
        location ~ ^/cgi-bin/([a-z-]+)(\?.*)?$ {
          root /usr/lib/cgi-bin;
          fastcgi_pass   unix:/var/run/fcgiwrap.socket;
          fastcgi_param SCRIPT_FILENAME  $document_root/$1;
          fastcgi_param PATH_INFO $uri;
          fastcgi_param QUERY_INFO $uri;
          # Fastcgi parameters, include the standard ones
          include /etc/nginx/fastcgi_params;

Note that this configuration makes all CGI programs in /usr/lib/cgi-bin available via nginx; this makes perfect sense for a desktop machine, but on a server, you might want to lock things down a bit more.