发布时间:2014-09-05 17:15:06作者:知识屋
笔者的nginx安装目录为/usr/local/nginx
虚拟机配置文件为/usr/local/nginx/conf/vhosts.conf
目前php fast-cgi已支持
以下操作均在su下完成
=====================
安装perl cgi模块
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
安装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 make install
===================
先在/bin目录下放置一个perl写的分发器,取名叫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);
&
linux一键安装web环境全攻略 在linux系统中怎么一键安装web环境方法
Linux网络基本网络配置方法介绍 如何配置Linux系统的网络方法
Linux下DNS服务器搭建详解 Linux下搭建DNS服务器和配置文件
对Linux进行详细的性能监控的方法 Linux 系统性能监控命令详解
linux系统root密码忘了怎么办 linux忘记root密码后找回密码的方法
Linux基本命令有哪些 Linux系统常用操作命令有哪些
Linux必学的网络操作命令 linux网络操作相关命令汇总
linux系统从入侵到提权的详细过程 linux入侵提权服务器方法技巧
linux系统怎么用命令切换用户登录 Linux切换用户的命令是什么
在linux中添加普通新用户登录 如何在Linux中添加一个新的用户
2012-07-10
CentOS 6.3安装(详细图解教程)
Linux怎么查看网卡驱动?Linux下查看网卡的驱动程序
centos修改主机名命令
Ubuntu或UbuntuKyKin14.04Unity桌面风格与Gnome桌面风格的切换
FEDORA 17中设置TIGERVNC远程访问
StartOS 5.0相关介绍,新型的Linux系统!
解决vSphere Client登录linux版vCenter失败
LINUX最新提权 Exploits Linux Kernel <= 2.6.37
nginx在网站中的7层转发功能