首先Nginx需添加perl-fastcgi支持,请参考:https://www.haiyun.me/archives/nginx-perl-fastcgi.html
安装Nagios:
#https://www.haiyun.me
useradd nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd www
cd /usr/local/src/
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz
tar zxvf nagios-3.4.1.tar.gz
cd nagios
./configure --with-command-group=nagcmd --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install
make install-init
make install-config
make install-commandmode
cd ../
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
tar zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
make
make install
ln -s /usr/local/nagios/share/ /home/wwwroot/nagios.www.haiyun.me
/etc/init.d/nagios start
Nginx配置:
server
{
listen 80;
server_name nagios.www.haiyun.me;
root /home/wwwroot/nagios.www.haiyun.me;
index index.php;
auth_basic "Login";
auth_basic_user_file /home/wwwroot/nagios.www.haiyun.me/passwd;
location ~ .*\.cgi?$
{
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
fastcgi_pass unix:/tmp/perl-fastcgi.sock;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
access_log none;
}
配置Nginx验证:
perl -e 'print crypt($ARGV[0], "pwdsalt")' passwd;echo
#生成passwd加密字符,将结果以user:passwd的方式填入/home/wwwroot/nagios.www.haiyun.me/passwd