fcgiwrap使nginx执行访问后缀为cgi的文件

fcgiwrap可以支持nginx访问后缀为cgi的文件
http://wiki.nginx.org/Fcgiwrap
Centos5.7 64位安装:
#yum install -y git-core build-essential libfcgi-dev autoconf lib tool automake
#cd /usr/local/src/ 

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


这里autoconf有版本要求:
# autoreconf -i
configure.ac:4: error: Autoconf version 2.61 or higher is required
configure.ac:4: the top level
autom4te: /usr/bin/m4 failed with exit status: 63
configure.ac:4: error: Autoconf version 2.61 or higher is required
configure.ac:4: the top level
autom4te: /usr/bin/m4 failed with exit status: 63
autoreconf: /usr/bin/autoconf failed with exit status: 63

# autoreconf -V
autoreconf (GNU Autoconf) 2.59
Written by David J. MacKenzie and Akim Demaille.
升级一下

到http://ftp.gnu.org/gnu/autoconf/  下载最新的
wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz

# tar xfv autoconf-latest.tar.gz 
# cd autoconf-2.69/
# ./configure --prefix=/usr/local/autoconf
# make && make install
# cd    /usr/local/src/fcgiwrap
/usr/local/autoconf/bin/autoreconf -i
然后就可以继续安装   fcgiwrap了
# ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for FCGX_Init in -lfcgi… no
configure: error: FastCGI library is missing

又没有FastCGI包。然后继续想办法安装
# wget  http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
# rpm -Uvh epel-release*rpm
# yum install fcgi-devel -y  

然后继续安装
# ./configure
#make && make install  
#mv  fcgiwrap  / usr / local / bin /

#vim /etc/init.d/fcgiwrap
#!/usr/bin/perl
 
use strict;
use warnings FATAL => qw( all );
 
use IO::Socket::UNIX;
 
my $bin_path = '/usr/local/bin/fcgiwrap';
my $socket_path = $ARGV[0] || '/tmp/cgi.sock';
my $num_children = $ARGV[1] || 1;
 
close STDIN;
 
unlink $socket_path;
my $socket = IO::Socket::UNIX->new(
    Local => $socket_path,
    Listen => 100,
);
 
die "Cannot create socket at $socket_path: $!\n" unless $socket;
 
for (1 .. $num_children) {
    my $pid = fork;
    die "Cannot fork: $!" unless defined $pid;
    next if $pid;
 
    exec $bin_path;
    die "Failed to exec $bin_path: $!\n"; 
}

chmod +x /etc/init.d/fcgiwrap

然后在nginx配置里面:
 fastcgi_pass. "fastcgi_pass unix:/tmp/cgi.sock;"

可以查看日志发现权限不对
chmod 777 /tmp/cgi.sock
好了,这样就可以访问了

我的nginx配置:
location ~ .*\.cgi$ {
                include fastcgi_params;
                fastcgi_pass    unix:/tmp/cgi.sock;
                fastcgi_index   smokeping.cgi;
                fastcgi_param   SCRIPT_FILENAME /var/www/html/smokeping/htdocs$fastcgi_script_name;
                }
这样我就用nginx来访问smokeping的页面了

你可能感兴趣的:(linux,nginx,fcgiwrap)