nginx+spawn fcgi正在提供原始cgi(二进制)文件内容(不执行它们)



我很难弄清楚为什么我的nginx+派生fastcgi提供原始二进制内容,而不是执行它们并提供结果。

目标是使用NginX配置Nagios Core 4.x。在这方面有很多很棒的博客;但没有人能说明我的问题。

我目前使用的是CentOS 6.6 NginX v1.0.15、spawn fcgi v1.6.3和php(php-fpm)v.4.30。

PHP文件托管工作得很好(PHP-fpm),**这只是我遇到的问题,我负责提供/cgi-bin/*.cgi文件。这是我的spwn fcgi环境:

cat << _EOF > /etc/sysconfig/spawn-fcgi
OPTIONS="-u apache -g apache -a 127.0.0.1 -p 9001 -C 32 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi"
_EOF

我的NginX配置:

server {
   listen 80;
   server_name monitor.mydomain.com;
   return 301 https://$server_name$request_uri;
}
server {
   listen 443;
   # Satisfy allows us to bypass authentication
   # for allowed ip addresses
   satisfy any;
   # Local Traffic only
   allow   192.168.0.0/24;
   allow   127.0.0.0/8;
   # drop rest of the world
   deny    all;
   server_name monitor.mydomain.com;
   root /usr/share/nagios;
   ssl_session_timeout  5m;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128:AES256:AES:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK';
   ssl_prefer_server_ciphers on;
   ssl_session_cache  builtin:1000  shared:SSL:10m;
   ssl on;
   ssl_certificate      /etc/pki/tls/certs/mydomain.com.crt;
   ssl_certificate_key  /etc/pki/tls/private/mydomain.com.key;
   index  index.php index.html index.htm;
   access_log  /var/log/nginx/nagios.access.log;
   error_log /var/log/nginx/nagios.error.log;
   # Security
   auth_basic            "Restricted Area";
   auth_basic_user_file  mynagios.htpasswd;
   location ~ .htaccess {
      deny all;
   }
   location / { 
      if ($uri ~* ".(ico|css|js|gif|jpe?g|png)(?[0-9]+)?$") {
         expires max;
         break;
      }
   }
   error_page  404              /404.html;
   location = /404.html {
      root   /usr/share/nginx/html;
   }
   # redirect server error pages to the static page /50x.html
   #
   error_page   500 502 503 504  /50x.html;
   location = /50x.html {
      root   /usr/share/nginx/html;
   }
   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
   #
   location ~ .php$ {
      try_files $uri = 404;
      fastcgi_split_path_info ^(.+.php)(/.+)$;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
   }
   #location ~ .cgi$ {
   location /nagios/cgi-bin/ {
      root   /usr/lib64/nagios/cgi;
      rewrite ^/nagios/cgi-bin/(.*).cgi /$1.cgi break;
      fastcgi_param  AUTH_USER $remote_user;
      fastcgi_param  REMOTE_USER $remote_user;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      #fastcgi_pass unix:/var/run/php-fcgi.sock;
      fastcgi_pass   127.0.0.1:9001;
      include      fastcgi_params;
   }
}

有问题的工具正在运行:

[root@fserver conf.d]# netstat -pnat | egrep '900(0|1)'
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      9054/php-fpm        
tcp        0      0 127.0.0.1:9001              0.0.0.0:*                   LISTEN      28888/php-cgi

再次,简而言之;这个配置"几乎"工作得很好,但是一个请求https://monitor.mydomain.com/nagios/cgi-bin/status.cgi服务器内容:

ELF>... <raw ugly content>

同样值得注意的是,我使用SELinux(为Nagios编写了我自己的模块),但在解决这个cgi问题之前,我已经禁用了它(所有的SELinux)。

你们能提供的任何建议都将非常棒!TIA

我解决了这个问题;如果有人和我有同样的问题,那是因为没有使用fcgiwrap。我只是按照说明编译了它。

使用fcgiwrap允许我执行fcgi返回的代码,而不是显示原始数据(我的问题):

cat << _EOF > /etc/sysconfig/spawn-fcgi
OPTIONS="-u apache -g apache -a 127.0.0.1 -p 9001 -f /usr/sbin/fcgiwrap -P /var/run/spawn-fcgi.pid"
_EOF
# Now restart spawn-fcgi
service spawn-fcgi restart

最新更新