\
ios
<span style="background-color: rgb(255, 255, 255); font-family: Tahoma, " microsoft="" yahei',="" simsun;="" font-size:="" 14px;="" line-height:="" 21px;="" color:="" rgb(68,="" 68,="" 68);="" "="">下面是nginx的錯誤日誌:
<span style="background-color: rgb(255, 255, 255); font-family: Tahoma, " microsoft="" yahei',="" simsun;="" font-size:="" 14px;="" line-height:="" 21px;="" color:="" rgb(68,="" 68,="" 68);="" "="">2012/06/27 15:15:18 [error] 28672#0: *2288 upstream closed prematurely FastCGI stdout while reading response header from upstream, client: 10.10.10.120, server: localhost, request: "POST /nagios/cgi-bin/cmd.cgi HTTP/1.1", upstream: "fastcgi://unix:/usr/local/nginx/logs/perl-fcgi.sock:", host: "10.10.10.201", referrer: "http://10.10.10.201/nagios/cgi-bin/cmd.cgi?cmd_typ=22&host=WEB1&service=HTTP"nginx
解決方案:web
nagios依賴 PHP 環境 和per 環境;
nginx不支持perl的CGI;
須要先 搭建perl環境,讓nginx支持perl的CGI方法不少,基本原理都是經過perl的FCGI模塊來實現,使用其中一種方法實現:
A. 安裝FCGI模塊
wget http://search.cpan.org/CPAN/auth ... RA/FCGI-0.73.tar.gz
tar xvzf FCGI-0.73.tar.gz
cd FCGI-0.73
perl Makefile.PL
make
make install
cd ..bash
B. 安裝FCGI-ProcManager模塊
wget http://search.cpan.org/CPAN/auth ... Manager-0.19.tar.gz
tar xvzf FCGI-ProcManager-0.19.tar.gz
cd FCGI-ProcManager-0.19
perl Makefile.PL
make
make install
cd ..ide
C. 安裝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
cd ..spa
wget http://search.cpan.org/CPAN/auth ... /IO-All-0.41.tar.gz
tar zxvf IO-All-0.41.tar.gz
cd IO-All-0.41
perl Makefile.PL
make
make install
cd ..
D. 下載Perl腳本
這個腳本的目的就是產生一個PERL的FastCGI接口,讓Nginx能夠以CGI方式處理Perl。
wget http://www.mike.org.cn/wp-content/uploads/2011/07/perl-fcgi.zip
unzip perl-fcgi.zip
cp perl-fcgi.pl /usr/local/webserver/nginx/
注:建議把這個腳本放在Nginx安裝目錄。
修改腳本權限
chmod 755 /usr/local/webserver/nginx/perl-fcgi.pl
E. 創建一個CGI啓動/中止腳本
這個SHELL腳本只是爲了方便管理上面的Perl腳本。腳本中的www爲nginx的運行用戶,請據本身的實際狀況調整。
注意事項:不能用root用戶執行(會提示). 要用與Nginx相同身份的用戶執行。不然可能會在Nginx Log中提示 Permision Denied。
vi /usr/local/webserver/nginx/start_perl_cgi.shunix
#!/bin/bash
#set -x
dir=/usr/local/webserver/nginx/rest
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/nullserver
chown www.www $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 www.www $dir/now_start_perl_fcgi.sh
chmod u+x $dir/now_start_perl_fcgi.sh
sudo -u www $dir/now_start_perl_fcgi.sh
echo "start perl-fcgi done"
}
case $1 in
stop)
stop
;;
start)
start
;;
restart)
stop
start
;;
esac
修改SHELL腳本權限chmod 755 /usr/local/webserver/nginx/start_perl_cgi.sh啓動腳本/usr/local/webserver/nginx/start_perl_cgi.sh start 正常狀況下在/usr/local/webserver/nginx/logs下生成perl-fcgi.sock這個文件,若是沒有生成,請檢查下上面的步聚