本文相关文档参考:
http://www.xtgly.com/2010/09/21/centos-5-5-nginx-nagios-%e5%ae%89%e8%a3%85%e9%85%8d%e7%bd%ae%e6%8c%87%e5%8d%97.htm
http://www.xtgly.com/2010/09/20/nginx-fastcgi-perl-pl%e3%80%81cgi%e6%94%af%e6%8c%81.htm

1.安装FCGI模块和FCGI-ProcManager模块
要记住http://search.cpan.org这个地址,可以搜索一些perl模块

wget http://search.cpan.org/CPAN/authors/id/B/BO/BOBTFISH/FCGI-0.70.tar.gz
wget http://www.cpan.org/modules/by-module/FCGI/FCGI-ProcManager-0.18.tar.gz
tar zxvf FCGI-0.70.tar.gz
cd FCGI-0.70
perl Makefile.PL
make
make install

按如上方法安装FCGI-ProcManager

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

 cpan install IO IO::All

3.取消nagios用户认证(方便调试)

 vi /usr/local/nagios/etc/cgi.cfg
找到use_authentication=1并把值改为0


4.下载perl-fcgi.pl脚本到/usr/local/nginx/
http://www.xtgly.com/wp-content/uploads/2010/09/perl-fcgi.zip
或者参考如下链接
http://wiki.codemongers.com/NginxSimpleCGI

再创建一个运行脚本,此脚本用来启动/停止perl-fcgi.pl

 touch /usr/local/nginx/sbin/perl-fcgi.sh
 chown -R www.www /usr/local/nginx/ 
 注意:www为nginx进程账号

 perl-fcgi.sh代码如下

  1. #!/bin/bash   
  2.         dir=/usr/local/nginx/  
  3.         stop ()   
  4.         {kill $(cat $dir/logs/perl-fcgi.pid)}  
  5.         start ()   
  6.         {sudo -u www /usr/local/nginx/perl-fcgi.pl -l $dir/logs/perl-fcgi.log -pid $dir/logs/perl-fcgi.pid -S $dir/logs/perl-fcgi.sock}  
  7.           
  8.           
  9.         case $1 in 
  10.         stop)   
  11.         stop   
  12.         ;;   
  13.         start)   
  14.         start   
  15.         ;;   
  16.         restart)   
  17.         stop   
  18.         start   
  19.         ;;   
  20.         esac 

5.修改nginx配置文件,我的配置供参考

  1. server {  
  2.         listen       80;  
  3.         server_name  localhost;  
  4.         root   /var/www/html;  
  5.         index  index.html index.htm index.php;  
  6.  
  7. location ~ .*\.(php|php5)?$ {  
  8.             fastcgi_pass   127.0.0.1:9000;  
  9.             fastcgi_index  index.php;  
  10.             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
  11.             include        fastcgi_params;  
  12.         }  
  13.  
  14. location ~ .*\.(cgi|pl)?$ {  
  15.         root                /usr/local/nagios/sbin;  
  16.         rewrite             ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;  
  17.         fastcgi_pass        unix:/usr/local/nginx/logs/perl-fcgi.sock;  
  18.         fastcgi_index       index.cgi;  
  19.         fastcgi_param       SCRIPT_FILENAME /usr/local/nagios/sbin/$fastcgi_script_name;  
  20.         include         fastcgi_params;  
  21.        }  
  22.  
  23. location /nginx_status {  
  24.                 stub_status on;  
  25.                 access_log off;  
  26.        }  

6.最后 

 ln -s /usr/local/nagios/share/ /var/www/html/nagios