CGI Support In Nginx(以nagios为例)
本文相关文档参考: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代码如下
[*]#!/bin/bash
[*] dir=/usr/local/nginx/
[*] stop ()
[*] {kill $(cat $dir/logs/perl-fcgi.pid)}
[*] start ()
[*] {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}
[*]
[*]
[*] case $1 in
[*] stop)
[*] stop
[*] ;;
[*] start)
[*] start
[*] ;;
[*] restart)
[*] stop
[*] start
[*] ;;
[*] esac
5.修改nginx配置文件,我的配置供参考
[*]server {
[*] listen 80;
[*] server_namelocalhost;
[*] root /var/www/html;
[*] indexindex.html index.htm index.php;
[*]
[*]location ~ .*\.(php|php5)?$ {
[*] fastcgi_pass 127.0.0.1:9000;
[*] fastcgi_indexindex.php;
[*] fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
[*] include fastcgi_params;
[*] }
[*]
[*]location ~ .*\.(cgi|pl)?$ {
[*] root /usr/local/nagios/sbin;
[*] rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
[*] fastcgi_pass unix:/usr/local/nginx/logs/perl-fcgi.sock;
[*] fastcgi_index index.cgi;
[*] fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin/$fastcgi_script_name;
[*] include fastcgi_params;
[*] }
[*]
[*]location /nginx_status {
[*] stub_status on;
[*] access_log off;
[*] }
[*]}
6.最后
ln -s /usr/local/nagios/share/ /var/www/html/nagios
页:
[1]