Serving CGI Scripts With Nginx On CentOS 6.3 - Page 2

3 Using Fcgiwrap


As there's no fcgiwrap package for CentOS 6.3, we must build it ourselves. First we install some prerequisites:

yum groupinstall 'Development Tools'
yum install fcgi-devel

Now we can build fcgiwrap as follows:

cd /usr/local/src/
git clone git://
cd fcgiwrap
autoreconf -i
make install



yum install spawn-fcgi

Open /etc/sysconfig/spawn-fcgi...

vi /etc/sysconfig/spawn-fcgi

... and modify the file as follows:

# You must set some working options before the "spawn-fcgi" service will work.
# If SOCKET points to a file, then this file is cleaned up by the init script.
# See spawn-fcgi(1) for all possible options.
# Example :
#OPTIONS="-u apache -g apache -s $SOCKET -S -M 0600 -C 32 -F 1 -P /var/run/ -- /usr/bin/php-cgi"


Create the system startup links for spawn-fcgi...

chkconfig --levels 235 spawn-fcgi on

... and start it as follows:

/etc/init.d/spawn-fcgi start


Now open your vhost configuration file...

vi /etc/nginx/nginx.conf


server {
   location /cgi-bin/ {
     # before getting gzipped)
     gzip off;

     root  /var/www/;

     # Fastcgi socket
     fastcgi_pass  unix:/var/run/fcgiwrap.socket;

     # Fastcgi parameters, include the standard ones
     include /etc/nginx/fastcgi_params;

     # Adjust non standard parameters (SCRIPT_FILENAME)
     fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;

Reload nginx:

/etc/init.d/nginx reload

Next we create our cgi-bin directory - /var/www/ because we defined root /var/www/; in the location /cgi-bin {} container:

mkdir /var/www/


vi /var/www/
#!/usr/bin/perl -w

     # Tell perl to send a html header.
     # So your browser gets the output
     # rather then <stdout>(command line
     # on the server.)

     # print your basic html tags.
     # and the content of them.
chmod 755 /var/www/

Open a browser and test the script:

If all goes well, you should get the following output:



About The Author


Share this page:

Suggested articles

0 Comment(s)

Add comment