Nginx+nagios installation Configuration
[Email protected] ~]# vi/etc/nginx/nginx.conf server {Listen the; server_name localhost; Auth_basic"Nagios Access"; Auth_basic_user_file/usr/local/nagios/passwd; Location/{root/usr/local/nagios/share; Index index.html index.htm index.php; } Location~ .*\. (PHP|PHP5)?$ {Root/usr/local/nagios/share; Fastcgi_pass127.0.0.1:9000; Fastcgi_index index.php; Include fastcgi.conf; } Location/Nagios {alias/usr/local/nagios/share; } Location/cgi-bin/Images {alias/usr/local/nagios/share/images; } Location/cgi-bin/stylesheets {alias/usr/local/nagios/share/stylesheets; } Location/cgi-Bin {alias/usr/local/nagios/sbin; } Location~ .*\. (CGI|PL)?$ {gzip off; Root/usr/local/nagios/sbin; Rewrite^/nagios/cgi-bin/(. *) \.cgi/$1. CGI Break; Fastcgi_pass Unix:/var/run/perl-Fastcgi.sock; Fastcgi_param Script_filename/usr/local/nagios/Sbin$fastcgi_script_name; Fastcgi_index index.cgi; Fastcgi_param Remote_user $remote _user; Fastcgi_param Http_accept_language en_US; Include Fastcgi_params; Fastcgi_read_timeout -; } Location/nagiosql/{alias/usr/local/nagios/Nagiosql; }}[[email protected]~]# Echo-en'Nagios:'>/usr/local/nagios/share/passwd [[email protected]~]# PERL-E'Print crypt ($ARGV [0], "Nagios")'passwd >>/usr/local/nagios/share/passwd
# Install PHP php-~]# yum install-y php php-~]#/etc/init.d/php-fpm start
# Install Perl fcgi[[email protected]~]# Yum install-y perl-Devel[[email protected] src]# wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.74.tar.gz[Email protected] src]# tar zxf fcgi-0.74. Tar.gz[[email protected] src]# CD FCGI-0.74[email protected] FCGI-0.74]# perl makefile.pl[[email protected] FCGI-0.74]# make &&Make Install[[email protected]~]# touch/usr/bin/fastcgi-wrapper.pl [[email protected]~]# chmod755/usr/bin/fastcgi-wrapper.pl [[email protected]~]# vi/usr/bin/fastcgi-wrapper.pl#!/usr/bin/perl use Fcgi;use socket;use POSIX qw (SETSID); require'syscall.ph'; &daemonize; # ThisKeeps the program alive or something after exec'ing Perl scriptsEND () {} BEGIN () {}*core::global::exit = Sub {die"fakeexit\nrc=". Shift ()."\ n"; }; Eval q{exit};if([email protected]) {exit unless [email protected]=~/^fakeexit/;}; &Main; Sub Daemonize () {chdir'/'Or Die"Can ' t chdir to/: $!"; Defined (My $pid= fork) or die"Can ' t fork: $!"; Exitif$pid; Setsid or die"Can ' t start a new session: $!"; Umask0;} Sub Main {# $socket= Fcgi::opensocket ("127.0.0.1:8999",Ten ); #use IP sockets $socket= Fcgi::opensocket ("/var/run/perl-fastcgi.sock",Ten ); $request= Fcgi::request (\*stdin, \*stdout, \*stderr, \%Req_params, $socket); if($request) {request_loop ()}; Fcgi::closesocket ($socket);} Sub Request_loop { while($request->accept () >=0) {#processing any STDIN input fromWebServer ( forcgi-POST actions) $stdin _passthrough="'; $req _len=0+ $req _params{'content_length'}; if(($req _params{'Request_method'} EQ'POST') && ($req _len! =0) {My $bytes _read=0; while($bytes _read <$req _len) {My $data="'; My $bytes= Read (STDIN, $data, ($req _len-$bytes _read)); Lastif($bytes = =0|| !defined ($bytes)); $stdin _passthrough.=$data; $bytes _read+=$bytes; }} #running the CGI appif((-X $req _params{script_filename}) && #can I Execute This? (-S $req _params{script_filename}) && #Is ThisFile empty? (-R $req _params{script_filename}) #can I read ThisFile?) {pipe (CHILD_RD, PARENT_WR); My $pid= Open (Kid_to_read,"-|"); Unless (defined ($pid)) {print ("content-type:text/plain\r\n\r\n"); Print"error:cgi app returned no output-"; Print"executing $req _params{script_filename} failed!\n"; Next } if($pid >0) {close (CHILD_RD); Print PARENT_WR $stdin _passthrough; Close (PARENT_WR); while(My $s = <KID_TO_READ>{print $s;} Close Kid_to_read; Waitpid ($pid,0); } Else { foreach$key (keys%req_params) {$ENV {$key}=$req _params{$key}; } # CD to the script's local Directory if($req _params{script_filename} =~/^ (. *) \/[^\/]+$/) {ChDir $1; } close (PARENT_WR); Close (STDIN); #fcntl (Child_rd, F_DUPFD,0); Syscall (&sys_dup2, Fileno (CHILD_RD),0); #open (STDIN,"<&child_rd"); EXEC ($req _params{script_filename}); Die ("exec failed"); } } Else{print ("content-type:text/plain\r\n\r\n"); Print"error:no such CGI app-$req _params{script_filename}"; Print"exist or isn't executable by this process.\n"; }}}[[email protected]~]# touch/etc/init.d/perl-Fastcgi[[email protected]~]# chmod755/etc/init.d/perl-fastcgi [[email protected]~]# vi/etc/init.d/perl-fastcgi#!/bin/sh## nginx– Thisscript starts and stops the Nginx daemon## chkconfig:- - the# Description:nginx isAn http (s) server, HTTP (s) reverse # Proxy and IMAP/POP3 proxy server# processname:nginx# config:/opt/nginx/conf/nginx.conf# pidfile:/opt/nginx/logs/Nginx.pid # Source function library:/etc/rc.d/init.d/functions # Source Networking configuration:/etc/sysconfig/Network # Check that networking isUp . [ "$NETWORKING"="No"] && exit0perlfastcgi="/usr/bin/fastcgi-wrapper.pl"Prog=$ (basename perl) Lockfile=/var/Lock/subsys/perl-fastcgi Start () {[-X $perlfastcgi] | | Exit5Echo-N $"starting $prog:"Daemon $perlfastcgi retval=$?Echo [$retval-eq0] &&Touch $lockfilereturn$retval} stop () {echo-N $"stopping $prog:"Killproc $prog-QUIT retval=$?Echo [$retval-eq0] && RM-F $lockfilereturn$retval} restart () {Stop start} reload () {echo-N $ "reloading $prog:" Killproc $nginx-HUP RETVAL=$?echo} force_reload () {restart}rh_status () {Status $prog} rh_status_q () {rh_status>/dev/NULL 2>&1} Case " $" inchstart) Rh_status_q&& exit0 $1 ;; Stop) Rh_status_q|| Exit0 $1 ;; Restart) $1 ;; Reload) Rh_status_q|| Exit7 $1 ;; Force-reload) force_reload;; status) Rh_status;; Condrestart|Try-restart) rh_status_q|| Exit0 ;; *) echo $"Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"Exit2Esac
Nagios installation Please refer to this article: http://www.cnblogs.com/caoguo/p/4981903.html
Nginx+nagios installation Configuration