TinySQL

In this post I will show you how to serve CGI scripts with Nginx on CentOS 6 using fcgiwrap. The article is designed that nginx is already set up and running as a service.

A simple solution

for small sites

  • 100% portability
  • Simple interface
  • The speed is limited only by the capacity your HDD
  • API for those who wish to spread the UI and ServerSide (in development)

CGI scripts with Nginx

In this post I will show you how to serve CGI scripts with Nginx on CentOS 6 using fcgiwrap.The article is designed that nginx is already set up and running as a service.

As there’s no fcgiwrap package for CentOS 6.0, you must build it yourself.

First install some prerequisites:

yum groupinstall 'Development Tools'
yum install fcgi-devel

Now you can build fcgiwrap:

cd /usr/local/src/
git clone git://github.com/gnosek/fcgiwrap.git
cd fcgiwrap
autoreconf -i
./configure
make
make install

This installs fcgiwrap to /usr/local/sbin/fcgiwrap.

Install the spawn-fcgi package which allows you to run fcgiwrap as a daemon:

yum install spawn-fcgi

Then modify your new spawn-fcgi configuration in /etc/sysconfig/ to look like this:

FCGI_SOCKET=/var/run/fcgiwrap.socket
FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
FCGI_USER=nginx
FCGI_GROUP=nginx
FCGI_EXTRA_OPTIONS="-M 0700"
OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"

Now you can start it like any other service. Don’t forget to add it to chkconfig

chkconfig –levels 2345 spawn-fcgi on

depending on your configuration

The last thing you need to do is to write the nginx configuration.

location /cgi-bin/ {
gzip off;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

As advertising
Site developer - Site! ltd.