nginx+fast-cgi模式下运行nagios

发布时间:2020-06-18编辑:脚本学堂
nginx+fast-cgi模式下运行nagios

想让nagios在nginx上运行,必需先让nginx支持perl和cgi解析的功能,需要用到fcgi-perl。

perl的fast-cgi起来后,nginx的配置:
 

复制代码 代码如下:

   server {
        listen       80;
        server_name  monitor.xxxx.com;

        root   /data1/www/monitor.xxxx.com;
        index  index.php index.html index.htm;

        access_log /data1/app/log/nginx/monitor.xxxx.com.log  combined;
        error_log  /data1/app/log/nginx/error-monitor.xxxx.com.log notice;

        allow 10.0.0.0/8;
        deny all;

        location ~ .php$ {

            root  /data1/www/monitor.xxxx.com;

            fastcgi_pass   unix:/data1/app/tmp/php-cgi.sock;
            fastcgi_index  index.php;
            include        fastcgi.conf;
        }

        location /nagios/ {
            alias /usr/share/nagios/;
            index index.html index.htm index.php;

            auth_basic "Nagios Access";
            auth_basic_user_file htpasswd.users;

            location ~ .php$ {
                root /usr/share;
                fastcgi_pass   unix:/data1/app/tmp/php-cgi.sock;
                fastcgi_index  index.php;
                include        fastcgi.conf;
            }
        }

        location ~ .*.(pl|cgi)$ {
            rewrite ^/nagios/cgi-bin/(.*).cgi /$1.cgi break;

            auth_basic "Nagios Access";
            auth_basic_user_file htpasswd.users;

            gzip off;
            include fastcgi_params;
            fastcgi_pass  127.0.0.1:8999;
            fastcgi_index index.cgi;
            fastcgi_param SCRIPT_FILENAME  /usr/lib64/nagios/cgi$fastcgi_script_name;
            fastcgi_param AUTH_USER $remote_user;
            fastcgi_param REMOTE_USER $remote_user;
        }
   }

然后重新生成认证文件htpasswd.users放在nginx的conf目录。重启nginx服务便可。

生成认证文件使用:
htpasswd -c htpasswd.users nagiosadmin

特别注意下面两个参数,一定要加上:
fastcgi_param AUTH_USER $remote_user;
fastcgi_param REMOTE_USER $remote_user;
否则进入nagios会提示没有认证。