Nginx + nagios +perl fcgi
 
通常使用:nginx 代理+ apache  CGI部分交给apache来处理
本文取消apache

Nginx nagios 安装略
 
安装perl cgi模块
wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.67.tar.gz      
tar -zxvf FCGI-0.67.tar.gz      
cd FCGI-0.67      
perl Makefile.PL     
make && make install

安装FCGI-ProcManager:
wget http://search.cpan.org/CPAN/authors/id/G/GB/GBJK/FCGI-ProcManager-0.18.tar.gz     
tar -xzxf FCGI-ProcManager-0.18.tar.gz      
cd FCGI-ProcManager-0.18      
perl Makefile.PL      
make      make install
 
下载nginx-fcgi脚本
放置在:/etc/nginx-fcgi
      注释掉nginx-fcgi.txt 中的
      if ( $> == “0″ ) {
      print “\n\tERROR\tRunning as a root!\n”;
      print “\tSuggested not to do so !!!\n\n”;
      exit 1;
      }
      否则会提示:ERROR   Running as a root!  Suggested not to do so !!!

启动方法:
/etc/nginx-fcgi -l /var/log/nginx/nginx-fcgi.log -pid /var/run/nginx-fcgi.pid -S /var/run/nginx-fcgi.sock
注意给 nginx-fcgi.sock 777的权限
运行前使用cpan 安装 FCGI;  Getopt::Long; IO::All;  Socket;
 
配置文件参考:/usr/local/nginx/conf/vhosts/nagios.conf
server
 {
   listen      80;
   server_name  IP;
root /usr/local/nagios/share;
index index.php;
location ~ .*\\.(php|php5)?$
{
fastcgi_pass  127.0.0.1:9000;
fastcgi_index index.php;
include  enable_php5.conf;
auth_basic \"Nagios Login pain\";
auth_basic_user_file /usr/local/nagios/etc/htpasswd;
}
location ~ .*\\.cgi$ {
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\\.cgi /$1.cgi break;
fastcgi_pass unix:/var/run/ng-fcgi.sock;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin/$fastcgi_script_name;
fastcgi_param HTTP_ACCEPT_LANGUAGE zh-cn;
include enable_php5.conf;
auth_basic \"Nagios Login pain\";
auth_basic_user_file /usr/local/nagios/etc/htpasswd;
         }
location /nagios/ {
alias /usr/local/nagios/share/;     
  }
 
enable_php5.conf 参考:
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_param HTTP_ACCEPT_ENCODING gzip,deflate;
 
如果报CGI 无法访问的错。请修改nagios里cgi.cfg use_authentication=1 给予执行权限

 

http://wiki.nginx.org/NginxSimpleCGI