Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get Nagios setup on NGiNX using PHP-FPM.

I installed fcgiwrap and and I'm able to execute a Perl script from the cgi-bin folder, but when I try to access Nagios, I get the following error in the NGiNX error log:

2012/08/23 16:40:21 [error] 8319#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client:, server: my.server.tld, request: "GET / HTTP/1.1", upstream: "fastcgi://", host: "my.server.tld"

I got this same error using the default locations, so I copied everything to different folders in order to keep the original installation files in-tact.

cp -R /usr/lib/cgi-bin/nagios3 /var/www/cgi-bin

cp -R /usr/share/nagios3/htdocs /var/www/html

This is what I have set in /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
        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;


This is what I have set in my /etc/nagios3/cgi.cfg


This is what I'm running, PHP wise:

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

Any ideas on what would cause this and/or how to fix it?

share|improve this question
up vote 1 down vote accepted

To clarify ErikA's answer:

It is saying "Primary script unknown" because NGiNX does not support running CGI directly. A helper program must be installed to process the CGI files and return the output to NGiNX.

This is why I had installed fcgiwrap, which processes the CGI files and passes the output to PHP-FPM, which is then processed by NGiNX, AFAIUI.

Although I thought I had started the init.d script for fcgiwrap, I had not.

I was able to determine this by running netstat -alnp | grep cgi, which returned no output until I started the script; /etc/init.d/fcgiwrap start

After I started it, I ran netstat -alnp | grep cgi again, and got the following output:

unix  2      [ ACC ]     STREAM     LISTENING     18955    11251/fcgiwrap      /var/run/fcgiwrap.socket

Once the script was running, and CGI was working, I no longer received this error, and Nagios worked.

Yay for migraines that attribute to cloudy thinking and stupid little mistakes!

share|improve this answer

Unless something drastic has changed in recent versions, Nagios is not a php application.

share|improve this answer
This is just for the web interface. – nojak Aug 23 '12 at 23:15
Right, unless you're using a third-party UI, the frontend is CGI, not PHP. – EEAA Aug 23 '12 at 23:18
I guess I should clarify that I moved all the files from their default locations, including the cgi files. /usr/lib/cgi-bin/nagios3 > /var/www/cgi-bin and /usr/share/nagios3/htdocs > /var/www/html. I couldn't get it working using the default locations, either, and got the same error, so I moved them to mess with it more without jacking up the original install files. – nojak Aug 23 '12 at 23:28
It's still not a php application. Take php our of the picture to reduce complexity and then see what you can get done. – EEAA Aug 23 '12 at 23:30
I was super awesome and had forgotten to start the fcgiwrap init.d script... – nojak Aug 23 '12 at 23:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.