4

Smells like a duplicate, I know, but I have now tried this Setup 5 Times over, and still I can't get this to work. Most of the configs are complicated with chroot and multi servers etc., but I have reduced this now to the simplest config possible. I want to understand how the fpm is setup with nginx in it's simplest form...Please bear with me.

Current Setup:

  • CentOS 7 64 bit
  • nginx 1.8.0 from Nginx repo
  • php 5.6 from Remi php56

Addition to /etc/nginx/conf.d/default.conf

    location ~ \.php$ {
      fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }

Addition and changes to /etc/php-fpm.d/www.conf

listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

Added the file /usr/share/nginx/html/info.php

<?php phpinfo();?>

Started both services

systemctl start nginx.service
systemctl start php-fpm.service

and Finally tail -f /var/log/nginx/error.log

2015/11/09 12:18:01 [error] 28638#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: xx.xxx.xxx.xxx, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "xxx.xx.xxx.xx"

So it seems that the FPM can't find the script, this much I have managed to understand, but according to the config, the Script file name is the document root and the script name. Script name is info.php, and according to the default config the root path is :

    location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}

Thus, if I concatenate this manually, I get

/usr/share/nginx/html/info.php

and this file exist

#ls -lah /usr/share/nginx/html/
total 20K
drwxr-xr-x 2 root root  4.0K Nov  9 12:35 .
drwxr-xr-x 3 root root  4.0K Apr 21  2015 ..
-rw-r--r-- 1 root root   537 Apr 21  2015 50x.html
-rw-r--r-- 1 root root   612 Apr 21  2015 index.html
-rw-r--r-- 1 root nginx   20 Nov  9 10:45 info.php

Can anybody give me an explanation why this is not working ?

  • IIRC "include fastcgi_params;" defines SCRIPT_FILENAME, can you try to move the include line "before" the fastcgi_param directive ? – Remi Collet Nov 9 '15 at 13:46
  • I tried swopping the fastcgi_param and inlcude... still no joy – Willem P. Botha Nov 9 '15 at 15:02
3

$document_root needs to pick up its value from a root directive at the same location or in a parent container. You seem to have root defined in a sibling container. Move root to the server container.

  • Moving the root entry from the sibling container location / did the trick. Rather silly, but simple. This is a standard default nginx installation. – Willem P. Botha Nov 9 '15 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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