我正在尝试使用PHP-FPM获取NGiNX上的Nagios设置。
我安装了fcgiwrap ,并且能够从cgi-bin文件夹执行Perl脚本,但是当我尝试访问Nagios时,在NGiNX错误日志中出现以下错误:
2012/08/23 16:40:21 [error] 8319#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.1.1.1, server: my.server.tld, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "my.server.tld"
我使用默认位置得到了同样的错误,所以我把所有东西都复制到了不同的文件夹中,以保持原始安装文件的完整性。
cp -R /usr/lib/cgi-bin/nagios3 /var/www/cgi-bin
cp -R /usr/share/nagios3/htdocs /var/www/html
这是我在/etc/nginx/sites-available/default
server { listen 80; server_name my.domain.tld; access_log /var/log/nginx/my.domain.tld.access.log; error_log /var/log/nginx/my.domain.tld.error.log; index index.php index.html index.htm; location / { root /var/www/html/; auth_basic "Restricted"; auth_basic_user_file /etc/nagios3/.htpasswd-users; } # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { fastcgi_pass localhost:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_intercept_errors on; } # FastCGI Wrapper location /cgi-bin/ { gzip off; root /var/www/; fastcgi_pass unix:/var/run/fcgiwrap.socket; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
这是我在/etc/nagios3/cgi.cfg设置的
physical_html_path=/var/www/html url_html_path=/
这就是我正在运行,PHP明智:
PHP 5.3.16-1~dotdeb.0 with Suhosin-Patch (cli) (built: Aug 17 2012 22:03:18) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd. with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
什么会导致这个和/或如何解决它的任何想法?
澄清ErikA的答案 :
这是说“主要脚本不明”,因为NGiNX不支持直接运行CGI 。 必须安装帮助程序来处理CGI文件并将输出返回到NGiNX 。
这就是为什么我安装了fcgiwrap ,它处理CGI文件并将输出传递给PHP-FPM ,然后由NGiNX , AFAIUI进行处理。
虽然我以为我已经启动了fcgiwrap的init.d脚本,但我没有。
我能够通过运行netstat -alnp | grep cgi来确定这一点 netstat -alnp | grep cgi ,直到我启动脚本才返回输出。 /etc/init.d/fcgiwrap start
开始之后,我运行了netstat -alnp | grep cgi 再次netstat -alnp | grep cgi ,并得到以下输出:
unix 2 [ ACC ] STREAM LISTENING 18955 11251/fcgiwrap /var/run/fcgiwrap.socket
一旦脚本运行, CGI工作,我不再收到这个错误, Nagios的工作。
耶为偏执属于多云思维和愚蠢的小错误!
除非在最近的版本中有些改变,Nagios不是一个PHP应用程序。