On a simple configuration nginx seems to be picking a random configuration file's document root to set as the $_SERVER['DOCUMENT_ROOT'] inside the PHP process it's attempting to fastcgi proxy to.
I've tried numerous configurations to try and scope the problem including nginx's debug log however to no avail
server {
listen 80;
server_name domain.co.uk;
index index.php;
error_log /var/log/nginx/domain.co.uk.error.log debug;
access_log /var/log/nginx/domain.co.uk.access.log;
root /var/www/domain.co.uk;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME /var/www/domain.co.uk/index.php;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/dev/shm/php.7.2.sock;
}
}
What happens is that the request picks a random other configuration and applies the document root from that to it. THe other configurations tend to have an auto_prepend
line in the PHP part of the config that auto_prepends a config.php file to every request. The strange part os that the config.php from another random site (it's never the same site twice in a row) has some includes in it - one of which is an autoloader. The autoloader tries to load a file which does not exist (error below)
2019/05/02 08:37:34 [error] 19105#0: *575827 FastCGI sent in stderr: "PHP message: PHP Fatal error: require(): Failed opening required '/var/www/domain.co.uk/resources/lib/class.autoloader.php' (include_path='.:/usr/share/php') in /var/www/www.anotherdomain.co.uk/config.php on line 84
What this error is saying is that it's prepending the config.php
file from /var/www/www.anotherdomain.co.uk/config.php
which is ultimately causing the error chain.
I am absolutely lost on how to start debugging this, I've been at it for two whole days and am none the wiser!
As I say, most of the other site configs have the auto_prepend
PARAM in the config so my question is really why is nginx picking one of those at random to apply to the config file in question?
If I change fastcgi_params
to remove $document_root
the problem goes away which tells me that nginx doens't know what the $document_root
is at the time of the request for some really strange reason.
Thanks in advance!