CGI with fcgiwrap¶
Use fcgiwrap to run CGI applications with NGINX.
Install on Debian/Ubuntu¶
Then include the example configuration in your server block:
Nginx Configuration File
server {
# ... other config ...
# FastCGI support for CGI scripts
include /etc/nginx/fcgiwrap.conf;
}
Manual Installation¶
Build fcgiwrap¶
Bash
apt install git-core build-essential libfcgi-dev autoconf libtool automake
cd /usr/local/src/
git clone git://github.com/gnosek/fcgiwrap.git
cd fcgiwrap
autoreconf -i
./configure
make
mv fcgiwrap /usr/local/bin/
Init Script¶
Save as /etc/init.d/fcgiwrap:
Perl
#!/usr/bin/perl
use strict;
use warnings FATAL => qw(all);
use IO::Socket::UNIX;
my $bin_path = '/usr/local/bin/fcgiwrap';
my $socket_path = $ARGV[0] || '/tmp/cgi.sock';
my $num_children = $ARGV[1] || 1;
close STDIN;
unlink $socket_path;
my $socket = IO::Socket::UNIX->new(
Local => $socket_path,
Listen => 100,
);
die "Cannot create socket at $socket_path: $!\n" unless $socket;
for (1 .. $num_children) {
my $pid = fork;
die "Cannot fork: $!" unless defined $pid;
next if $pid;
exec $bin_path;
die "Failed to exec $bin_path: $!\n";
}
Make executable:
Add to /etc/rc.local: