Serving plain CGI scripts with nginx

nginx cgi ruby

nginx as a super-duper modern and fast web server doesnt have plain CGI support, only FCGI. So how to run some script without keeping full fedged FCGI process running in background?


fcgiwrap is lightweight script to run plain old CGI files by FCGI protocol:

apt-get install fcgiwrap
cp /var/share/fcgiwrap/examples/nginx.conf /etc/nginx/fcgiwrap.conf

Include fcgiwrap.conf in /etc/nginx/nginx.conf

include fcgiwrap.conf;

For example, to execute ruby files, locating in /var/www/site, configure fcgiwrap.conf as follows:

location ~ \.rb$ {
  root /var/www/site
  fastcgi_param SCRIPT_FILENAME /var/www/site$fastcgi_script_name;


#!/usr/bin/env ruby
print "Content-type: text/plain\n\n"
print "hello\n"