当前位置:  首页  >  服务器技术  >  Linux/unix  >  Linux教程

Nginxfastcgiperl(pl、cgi)支持

1.安装FCGI模块#wgethttp:search.cpan.orgCPANauthorsidBBOBOBTFISHFCGI-0.70.tar.gz#tarzxvfFCGI-0.70.tar.gz#cdFCGI-0.70#perlMakefile.PL#make#makeinstall2.安装IO和IO::ALL模块#wgethttp:search.cpan.orgCPANa

1. 安装FCGI模块

# wget http://search.cpan.org/CPAN/authors/id/B/BO/BOBTFISH/FCGI-0.70.tar.gz
# tar zxvf FCGI-0.70.tar.gz
# cd FCGI-0.70
# perl Makefile.PL
# make
# make install

2. 安装 IO 和 IO::ALL模块

# wget http://search.cpan.org/CPAN/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
# wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.41.tar.gz
# tar zxvf IO-All-0.41.tar.gz
# cd IO-All
# perl Makefile.PL
# make
# make install

3. Perl脚本

下载Perl脚本

见本文最后

我把这个脚本放在 /usr/local/nginx/perl-fcgi.pl
# chmod 755 /usr/local/nginx/perl-fcgi.pl

4.cgi启动/停止脚本 (nobody为nginx的运行用户)

# vi /usr/local/nginx/start_perl_cgi.sh

#!/bin/bash
#set -x
dir=/usr/local/nginx

stop ()
{
#pkill  -f  $dir/perl-fcgi.pl
kill $(cat $dir/logs/perl-fcgi.pid)
rm $dir/logs/perl-fcgi.pid 2>/dev/null
rm $dir/logs/perl-fcgi.sock 2>/dev/null
echo "stop perl-fcgi done"
}

start ()
{
rm $dir/now_start_perl_fcgi.sh 2>/dev/null

chown nobody.root $dir/logs
echo "$dir/perl-fcgi.pl -l $dir/logs/perl-fcgi.log -pid $dir/logs/perl-fcgi.pid -S $dir/logs/perl-fcgi.sock" >>$dir/now_start_perl_fcgi.sh

chown nobody.nobody $dir/now_start_perl_fcgi.sh
chmod u+x $dir/now_start_perl_fcgi.sh

sudo -u nobody $dir/now_start_perl_fcgi.sh
echo "start perl-fcgi done"
}

case $1 in
stop)
stop
;;
start)
start
;;
restart)
stop
start
;;
esac

 

# chmod 755 /usr/local/nginx/start_perl_cgi.sh
# 启动脚本
# /usr/local/nginx/start_perl_cgi.sh start
正常情况下在/usr/local/nginx/logs 下生成 perl-fcgi.sock 这个文件,如果没有生成,那就要检查下上面的步聚了.

5. 配置nginx

server {
    listen       80;
    server_name  _;
    location / {
        root   /usr/local/nginx/html;
        index  index.html index.htm index.cgi;
    }
    location ~ .*\.(pl|cgi)?$
    {
      gzip off;
      root   /data/nginx/html;
      fastcgi_pass  unix:/usr/local/nginx/logs/perl-fcgi.sock;
      fastcgi_index index.cgi;
      fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
      fastcgi_param  SERVER_SOFTWARE    nginx;
      fastcgi_param  QUERY_STRING       $query_string;
      fastcgi_param  REQUEST_METHOD     $request_method;
      fastcgi_param  CONTENT_TYPE       $content_type;
      fastcgi_param  CONTENT_LENGTH     $content_length;
      fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
      fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
      fastcgi_param  REQUEST_URI        $request_uri;
      fastcgi_param  DOCUMENT_URI       $document_uri;
      fastcgi_param  DOCUMENT_ROOT      $document_root;
      fastcgi_param  SERVER_PROTOCOL    $server_protocol;
      fastcgi_param  REMOTE_ADDR        $remote_addr;
      fastcgi_param  REMOTE_PORT        $remote_port;
      fastcgi_param  SERVER_ADDR        $server_addr;
      fastcgi_param  SERVER_PORT        $server_port;
      fastcgi_param  SERVER_NAME        $server_name;
      fastcgi_read_timeout   60;
     }
}

6.Perl探针测试

本文相关文件下载

Perl探针 与 Perl脚本下载地址:

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /pub/2011/09/27/Nginx fastcgi perl (pl、cgi)支持/

 

吐了个 "CAO" !
扫码关注 PHP1 官方微信号
PHP1.CN | 中国最专业的PHP中文社区 | PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | PHP问答
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved PHP1.CN 第一PHP社区 版权所有