Thursday, November 6, 2014

Run fcgiwrap with nginx under Slackware

I need to do some test on perl CGI scripts, but with NGINX server, it is not supported directly to run those CGI scripts.  Search around, there is this fcgiwrap tool.  It looks exactly like what I need for the simple test.

Fcgiwrap depends on fcgi library, which has a SlackBuild script.  I install the fcgi library with sbopkg, and proceed to write a SlackBuild script for fcgiwrap.  The fcgiwrap is a very simple program, it has only one C file for the main program.  But it needs a spawning parent to control it, the author provide a simple perl script (on the main page of the fcgirwap project.) to spawn the fcgiwrap program.  I also borrow the startup script from Nginx's FastCGI example and modified a little and name it rc.spawn-fcgi.  Both the scripts are included in the SlackBuild package that I have submitted.

After installing it, I add the following section into the server section of nginx.conf file:
  location ~ \.pl$ {
     root /var/www/cgi;
     try_files $uri =404;
            include        fastcgi_params;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     fastcgi_pass unix:/tmp/cgi.sock;
   }
After started the spawn-fcgi and reload nginx's config, the perl CGI works without problem.
Post a Comment