我很难弄清楚为什么我的 nginx + spawn-fastcgi 提供原始二进制内容而不是执行它们并提供结果。
目标是使用 NginX 配置 Nagios Core 4.x。这方面有很多很棒的博客;但没有人阐明我的问题。
我目前正在使用 CentOS 6.6 NginX v1.0.15、spawn-fcgi v1.6.3 和 php (php-fpm) v5.4.30。
PHP 文件托管工作得很好(php-fpm),**它只是 spawn-fcgi 内容我遇到的问题是我负责提供 /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