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?
You should have a
location
section to handle PHP requests configured similarly to this:(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 theserver
section of the configuration file, not thelocation
section. This is one of the most common nginx misconfigurations.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:
becomes:
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.
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 customSCRIPT_FILENAME
like this:As the
SCRIPT_FILENAME
was being overwritten.If you're using aliases in your location blocks, an unhandled 404 error can also exhibit this behavior. You can see this if the page displayed in the browser is the simple text "File not found" as opposed to the prettier formatted (centered) nginx 404 page. Essentially, it's really saying the 404 page can't be found.
To solve, add an additional
try_files $uri =404
line in your location block and reload the nginx config. In addition to what Michael Hampton said about solving a specific security vulnerability, this also allows the fastcgi handler to override the alias definition and find the 404 script in the default location.about line 149, change php user && user group
I test it successful now.
I have seen :
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.