I am apparently not the only one with this problem, but after trying every suggested solution for couple I reached I point where I don't know what to do.
I am running Ubuntu 16.04, NGinx and PHP-FPM.
The nginx.conf is the default one, I only set a more informative log format.
The user rights seem to be okay: NGinx and PHP_FPM run under user www-data. Document-Root owner is www-data. FPM-Pool owner is www-data. Socket-file is there and writable.
I already tried setting folder- and file-permissions to the weakest (chmod 777): No result.
This is my server.conf, as you can see from commented lines, I tried a bunch of tricks - with no effect:
server {
listen 8080;
# listen 8080 default_server;
# listen [::]:8080 default_server;
server_name example.com www.example.com
root /var/www/nginx/;
index index.php;
access_log /var/log/nginx/scripts.log scripts;
gzip on;
gzip_comp_level 3;
gzip_types text/plain text/css application/javascript image/*;
location ~ \.php$ {
if ($uri !~ "^/uploads/") {
fastcgi_pass unix:/run/php/php-fpm-www.sock;
}
include fastcgi.conf;
# include snippets/fastcgi-php.conf;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
# Block access to .htaccess
location ~ \.htaccess {
deny all;
}
}
That's the fpm-pool config:
[www]
listen = /run/php/php-fpm-$pool.sock
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
php_admin_flag[allow_url_fopen] = off
php_admin_flag[allow_url_include] = off
php_admin_value[memory_limit] = 128M
pm = dynamic
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /
chroot = /var/www/nginx/
php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
catch_workers_output = yes
This is the output of the nginx' access.log:
/var/www/nginx/index.php > GET /index.php HTTP/1.1
And that's the actual error.log:
2018/08/29 17:34:27 [error] 24020#24020: *47 FastCGI sent in stderr: "Unable to open primary script: /var/www/nginx/index.php (No such file or directory)" while reading response header from upstream, client: 213.61.37.18, server: example.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php-fpm-www.sock:", host: "example.com:8080"
I found the error for myself after the hint of @michael - thanks for the enlightenment.
I am using chroot, because the goal is to "jail" every website in it's own environment / folder. So I set the root of this particular environment to the real filesystem location /var/www/nginx.
Inside the server configuration of NGinx I pass the fastcgi parameter SCRIPT_FILENAME with a leading $document_root.
In NGinx $document_root references the root-directive. The $document_root is, of course /var/www/nginx
But the PHP-environment has a "changed root" (/ means /var/www/nginx). That means, that PHP now is looking for index.php in the folder /var/www/nginx. But as the root folder is only "virtual", PHP's /var/www/nginx actualy points to this location on the real filesystem: /var/www/nginx/var/www/nginx.
So changing the parameter to this will fix the error.