一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Linux系统配置nginx支持.cig的步骤

时间:2014-09-20 编辑:简简单单 来源:一聚教程网

word-spacing: 0px; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-">说明:
web环境:php+nginx+mysql
nginx安装目录:/usr/local/nginx
nginx配置文件:/usr/local/nginx/conf/nginx.conf
nginx默认站点目录:/usr/local/nginx/html/
需求:让nginx能够解析.cgi后缀的文件
具体操作:
一、安装perl-fcgi依赖包,通过安装perl-fcgi来支持nginx运行.cgi
yum install perl-CPAN perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
二、安装perl
cd /usr/local/src
wget http://www.cpan.org/src/5.0/perl-5.20.0.tar.gz #下载安装包,需要提前安装wget工具
tar -xzf perl-5.20.0.tar.gz #解压
cd perl-5.20.0 #进入目录
./Configure -des -Dprefix=/usr/local/perl #配置
make #编译
make install #安装
mv /usr/bin/perl /usr/bin/perl.bak #备份系统默认的perl
ln -s /usr/local/perl/bin/perl /usr/bin/perl #把刚刚安装好的新perl软连接到perl在系统中的默认位置
perl -v #查看perl版本
Linux系统配置nginx支持.cig的步骤
三、安装perl支持模块
1、安装perl fcgi模块
cd /usr/local/src
wget http://www.cpan.org/authors/id/F/FL/FLORA/FCGI-0.74.tar.gz
tar zxvf FCGI-0.74.tar.gz
cd FCGI-0.74
perl Makefile.PL #配置
make
make install
2、安装FCGI-ProcManager模块
cd /usr/local/src
wget http://www.cpan.org/authors/id/B/BO/BOBTFISH/FCGI-ProcManager-0.24.tar.gz
tar zxvf FCGI-ProcManager-0.24.tar.gz
cd FCGI-ProcManager-0.24
perl Makefile.PL
make
make install
3、安装IO模块
cd /usr/local/src
wget http://www.cpan.org/authors/id/G/GB/GBARR/IO-1.25.tar.gz
tar zxvf IO-1.25.tar.gz
cd IO-1.25
perl Makefile.PL
make
make install
4、安装IO::ALL模块
cd /usr/local/src
wget http://www.cpan.org/authors/id/I/IN/INGY/IO-All-0.79.tar.gz
tar zxvf IO-All-0.79.tar.gz
cd IO-All-0.79
perl Makefile.PL
make
make install
四、配置nginx支持.cgi
1、vi /usr/local/nginx/perl-fcgi.pl #编辑,添加以下代码
#!/usr/bin/perl
#
# author Daniel Dominik Rudnicki
# thanks to: Piotr Romanczuk
# email daniel@sardzent.org
# version 0.4.3
# webpage http://www.nginx.eu/
#
# BASED @ http://wiki.codemongers.com/NginxSimpleCGI
#
#
# use strict;
use FCGI;
use Getopt::Long;
use IO::All;
use Socket;
sub init {
GetOptions( "h" => $help,
"verbose!"=>$verbose,
"pid=s" => $filepid,
"l=s" => $logfile,
"S:s" => $unixsocket,
"P:i" => $unixport) or usage();
usage() if $help;
print " Starting Nginx-fcgin" if $verbose;
print " Running with $> UID" if $verbose;
print " Perl $]" if $verbose;
if ( $> == "0" ) {
print "ntERRORtRunning as a root!n";
print "tSuggested not to do so !!!nn";
exit 1;
}
if ( ! $logfile ) {
print "ntERRORt log file must declaredn"
. "tuse $0 with option -l filenamenn";
exit 1;
}
print " Using log file $logfilen" if $verbose;
"nn" >> io($logfile);
addlog($logfile, "Starting Nginx-cfgi");
addlog($logfile, "Running with $> UID");
addlog($logfile, "Perl $]");
addlog($logfile, "Testing socket options");