The author's nginx installation directory is/usr/local/nginx virtual machine configuration file/usr/local/nginx/conf/vhosts. conf phpfast-cgi currently supports the following operations to install the perlcgi module wgethttp: // www.cpan.org/modules/by-module/FC in su:
The installation directory of nginx is/usr/local/nginx.
The virtual machine configuration file is/usr/local/nginx/conf/vhosts. conf.
Currently, php fast-cgi supports
The following operations are completed under su:
==================================
Install the perl cgi module
Wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.67.tar.gz
Tar-zxvf FCGI-0.67.tar.gz
Cd FCGI-0.67
Perl Makefile. PL
Make & make install
Install FCGI-ProcManager:
Wget http://search.cpan.org/CPAN/authors/id/G/GB/GBJK/FCGI-ProcManager-0.18.tar.gz
Tar-xzxf FCGI-ProcManager-0.18.tar.gz
Cd FCGI-ProcManager-0.18
Perl Makefile. PL
Make install
==============================
First, place a perl-written distributor in the/bin directory named perl-fcgi.
Vi/bin/perl-cgi
#! /Usr/bin/perl-w
Use FCGI;
Use Socket;
Use FCGI: ProcManager;
Sub shutdown {FCGI: CloseSocket ($ socket); exit ;}
Sub restart {FCGI: CloseSocket ($ socket); & main ;}
Use sigtrap handler, & shutdown, normal-signals;
Use sigtrap handler, & restart, HUP;
Require syscall. ph;
Use POSIX qw (setsid );
# & Daemonize; we dont daemonize when running under runsv
# This keeps the program alive or something after execing perl scripts
END (){}
BEGIN (){}
{
No warnings;
* CORE: GLOBAL: exit = sub {die "fakeexitrc =". shift ()."";};
};
Eval q {exit };
If ($ @){
Exit unless $ @ = ~ /^ Fakeexit /;
}
& Main;
Sub daemonize (){
Chdir/or die "Cant chdir to/: $! ";
Defined (my $ pid = fork) or die "Cant fork: $! ";
Exit if $ pid;
Setsid () or die "Cant start a new session: $! ";
Umask 0;
}
Sub main {
$ Socket = FCGI: OpenSocket ("127.0.0.1: 10081", 10); # use IP sockets
# $ Socket = FCGI: OpenSocket ("/var/run/nginx/perl_cgi-dispatch.sock", 10 );
# Use UNIX sockets-user running this script must have w access to the nginx folder !!
# Foreach $ item (keys % ENV) {delete $ ENV {$ item };}
$ Proc_manager = FCGI: ProcManager-> new ({n_processes => 5 });
# $ Socket = FCGI: OpenSocket ("/opt/nginx/fcgi/cgi. sock", 10)
; # Use UNIX sockets-user running this script must have w access to the nginx folder !!
$ Request =
FCGI: Request (* STDIN, * STDOUT, * STDERR, \ % req_params, $ socket,
& FCGI: FAIL_ACCEPT_ON_INTR );
$ Proc_manager-> pm_manage ();
If ($ request) {request_loop ()}
FCGI: CloseSocket ($ socket );
}
Sub request_loop {
While ($ request-> Accept ()> = 0 ){
$ Proc_manager-> pm_pre_dispatch ();
# Processing any STDIN input from WebServer (for CGI-POST actions)
$ Stdin_passthrough =;
{No warnings; $ req_len = 0 + $ req_params {CONTENT_LENGTH };};
If ($ req_params {REQUEST_METHOD} eq POST) & ($ req_len! = 0 ))
{
My $ bytes_read = 0;
While ($ bytes_read <$ req_len ){
My $ data =;
My $ bytes = read (STDIN, $ data, ($ req_len-$ bytes_read ));
Last if ($ bytes = 0 |! Defined ($ bytes ));
$ Stdin_passthrough. = $ data;
$ Bytes_read + = $ bytes;
}
}
# Running the cgi app
If (
(-X $ req_params {SCRIPT_FILENAME}) & # can I execute this?
(-S $ req_params {SCRIPT_FILENAME}) & # Is this file empty?
(-R $ req_params {SCRIPT_FILENAME}) # can I read this file?
)
{
Pipe (CHILD_RD, PARENT_WR );
Pipe (PARENT_ERR, CHILD_ERR );
My $ pid = open (CHILD_O, "-| ");
Unless (defined ($ pid )){
Print ("Content-type: text/plain ");
Print
"Error: CGI app returned no output-Executing $ req_params {SCRIPT_FILENAME} failed! ";
Next;
}
$ Oldfh = select (PARENT_ERR );
$ | = 1;
Select (CHILD_O );
&