Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've hit a wall whilst setting up a site using nginx / fpm. The page displays "File not found", and this appears in the nginx error.log:

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

I'm new to both nginx and fpm, and that error message means nothing to me (even the google machine hasn't helped!). Can anyone shed any light onto what could be happening?

share|improve this question
    
Could you add the part of your nginx config where you defin the PHP handling? –  Christopher Perrin Jul 9 '12 at 19:22
    
For me the following article helped: nginxlibrary.com/resolving-no-input-file-specified-error. Generally this error comes if there is a problem with the SCRIPT_FILENAME. –  white_gecko Apr 15 '13 at 12:54

4 Answers 4

up vote 15 down vote accepted

You should have a location section to handle PHP requests configured similarly to this:

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include         fastcgi_params;
    }

(The extra try_files resolves a security vulnerability which could allow arbitrary files to be executed as PHP.)

In addition, your root should be defined in the server section of the configuration file, not the location section. This is one of the most common nginx misconfigurations.

share|improve this answer
    
+1 for that misconfigurations article - really worth a read, particularly if you're learning Nginx. Well written, entry-level, with several great tips! –  Steve Jan 20 at 1:22

This is a note for passenger installs.

I just installed nginx from source via passenger which caused a problem with php5-fpm. The default nginx.conf makes use of the problem described by Michael Hampton. The solution is to remove the blok around the root and index directives, so:

location / {
    root html
    index index.html index.htm
}

becomes:

root html
index index.html index.htm

Furthermore the php block is incorrectly set up. See Michael Hamptons answer for the correct way to it.

An additional note could be that if php5-fpm is set up to use sockets point the fastcgi_pass parameter in the php block in nginx.conf to the socket setup in /etc/php5/fpm/pool.d/www.conf.

share|improve this answer

I have seen :

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

in a server I placed under high load when stress testing. My suspicion, still to be confirmed, is that the available file handles from the OS were exhausted. In which case php-fpm cannot get a reference to the file.

I realise this is speculative but it certainly fits my scenario and might also help someone else.

share|improve this answer

I Just had this problem in a new version of nginx. (config taken from an older version)

What I had to do was place the include fastcgi_params; above my custom SCRIPT_FILENAME like this:

location @web {
        try_files $uri =404;
        include         fastcgi_params;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_param   SCRIPT_FILENAME  $document_root/index.php;
}

As the SCRIPT_FILENAME was being overwritten.

share|improve this answer

Your Answer

 
discard

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.