Nginx to serve CGI

Grzegorz Nosek grzegorz.nosek at
Thu Sep 6 21:12:11 MSD 2007

2007/9/6, Riku Räisänen <riku at>:
> Igor, could you re-evaluate the possibility of piping through CGI from
> nginx? There are still lots of legacy apps that are and will stay written in
> CGI. And I wouldn't want to throw in apache just for that. I couldn't get
> the perl dispatcher to work correctly, either.

Let me copy my earlier mail from this list (with apologies to the
regulars. Maybe I should add it to the wiki... and finally publish my
Have a look at

You need libfcgi (lib and headers, refer to your distro for details)
and compile it like this:

gcc -Wall -Wextra -Werror -pedantic -O2 fcgiwrap.c -o fcgiwrap -lfcgi

You can run it under a process manager (e.g. spawn-fcgi from lighttpd
if you're desperate ;) ) and simply direct requests to it via

* Don't run as root! The wrapper doesn't drop privileges, so beware.
* Absolutely no warranty etc. If it breaks, you get to keep the pieces.
* The wrapper may service only one request at a time, but CGI usually
isn't performance-sensitive anyway :)
* Set up DOCUMENT_ROOT etc. in nginx before passing the request
* You may need to hack around nginx if you want to support PATH_INFO
(/index.cgi/foobar) - I may publish my repo if I find the time
* As far as I tested, it works fine.

 Grzegorz Nosek

More information about the nginx mailing list