nagios结合nginx、spawn-fcgi
Nagios的安装配置就不说了,主要讲ngaios结合nginx的一些注意事项,众所周知apache可以用php来结合nagios,而在nginx中只能用fastcgi来结合nagios,fastcgi简单的说就是启动后长驻内存,这样就不用每次都fork出来进程,节约了宝贵的系统资源。让nginx支持fastcgi也有多种方式,我采用的是spawn-fcgi,要注意的是,nginx支持php是用spawn-fcgi来完成的,而同时也要让nginx支持cgi这可以通过perl脚本来实现,下面说说配置过程,
server {
listen 80;
server_name localhost;
root /usr/local/nginx/html;
index index.html index.htm index.php;
allow all;
#charset koi8-r;
charset utf-8;
access_log logs/host.access.log main;
location /nagios {
index index.php;
alias /usr/local/nagios/share;
auth_basic "Nagios Access";
auth_basic_user_file "/usr/local/nagios/etc/htpasswd.users";
allow all;
}
location = /nagios {
rewrite ^/nagios/ permanent;
}
location ~ .*\.(php|php5)?$
{
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;/php-cgi的监听端口。
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.cgi$ {
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;
fastcgi_pass unix:/var/run/nginx-fcgi.sock;这是perl脚本的sock目录,该文件一定要是777权限
fastcgi_index index.cgi;
include fastcgi.conf;
fastcgi_param HTTPACCEPT_LANGUAGE zh-cn;
auth_basic "Nagios Access";
auth_basic_user_file "/usr/local/nagios/etc/htpasswd.users";
fastcgi_param AUTH_USER $remote_user; //这2句一定要加,不加的话,会报未授权,无法查看主机和服务状态。
fastcgi_param REMOTE_USER $remote_user;
allow all;
}
以上nginx的配置,注意红色字体的部分。
/usr/local/spawn/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u daemon -g daemon -f /usr/bin/php-cgi 启动php-cgi
usr/local/nginx/sbin/nginx-fcgi.pl -S /var/run/nginx-fcgi.sock -l /var/log/nginx/nginx-cfgi.log -pid /var/run/nginx-fcgi.pid //启动nginx-fcgi
chmod 777 /var/run/nginx-fcgi.sock
阅读(2613) | 评论(0) | 转发(0) |