涛子 - 简单就是美

成单纯魁增,永继振国兴,克复宗清政,广开家必升

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#Spawn-FCGI
一个通用的FastCGI管理服务器,它是lighttpd中的一部份,很多人都用Lighttpd的Spawn-FCGI进行FastCGI模式下的管理工作

#fcgiwrap(Simple FastCGI wrapper for CGI scripts) 
为那些不支持直接运行CGI脚本的Web服务器提供一种运行CGI脚本的方式。

nagios运行cgi,所以需要fcgiwrap为nginx解析cgi。

yum -y install fcgiwrap-1.1.0-1.gf.el7.x86_64.rpm
yum -y install php-fpm spawn-fcgi
# php-fpm
/etc/php-fpm.d/www.conf
listen = /var/run/php-fpm.sock

systemctl restart php-fpm
#spawn-fcgi & fcgiwrap

cat > /etc/sysconfig/spawn-fcgi << EOF
FCGI_SOCKET=/var/run/fcgiwrap.sock
FCGI_PROGRAM=/usr/sbin/fcgiwrap
FCGI_USER=nginx
FCGI_GROUP=nginx
FCGI_EXTRA_OPTIONS="-M 0700"
OPTIONS="-u \$FCGI_USER -g \$FCGI_GROUP -s \$FCGI_SOCKET -S \$FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- \$FCGI_PROGRAM"
EOF

systemctl restart spawn-fcgi

/etc/nginx/conf.d/nagios.conf 没用alias,直接用虚拟主机方式,注意nagios的请求是以^nagios开头的,需要rewrite,我的配置log不报错,但是页面的cgi查询出不来

server {
   listen 80;
   server_name nagios.local;

   access_log /var/log/nginx/nagios.access.log;
   error_log /var/log/nginx/nagios.error.log info;

   auth_basic "Nagios Restricted Access";
   auth_basic_user_file /etc/nagios/passwd;

   location / {
      root /usr/share/nagios/html;
      index index.php;
      rewrite ^/nagios/(js|images|stylecss)/(.*)$ /$1/$2 break;
   }
   
   location ~ \.php$ {
      include fastcgi_params;
      fastcgi_pass unix:/var/run/php-fpm.sock;
      fastcgi_param SCRIPT_FILENAME /usr/share/nagios/html/$fastcgi_script_name;
   }

   location ~ \.cgi$ {
      root /usr/lib64/nagios/cgi-bin;
      rewrite ^/nagios/cgi-bin/(.*)$ /$1 break;
      rewrite ^/cgi-bin/(.*)$ /$1 break;
   
      include fastcgi_params;
      fastcgi_pass unix:/var/run/fcgiwrap.sock;

      fastcgi_param AUTH_USER $remote_user;
      fastcgi_param REMOTE_USER $remote_user;
      fastcgi_param SCRIPT_FILENAME /usr/lib64/nagios/cgi-bin$fastcgi_script_name;  
   }
}

/etc/nginx/conf.d/pnp4nagios.conf 没用alias,直接用虚拟主机方式,其他正常,仅search功能不正常

server {
    listen 80;
    server_name pnp4nagios.local;

    access_log /var/log/nginx/pnp4nagios.access.log;
    error_log /var/log/nginx/pnp4nagios.error.log info;

    auth_basic "Nagios Restricted Access";
    auth_basic_user_file /etc/nagios/passwd;

    location / {
      root /usr/share/pnp4nagios;
      index index.php;
    }

    location ~ ^(.*\.php)(.*)$ {
        root /usr/share/pnp4nagios;
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
   }
}
posted on 2017-08-01 09:50  北京涛子  阅读(272)  评论(0编辑  收藏  举报