This is part of my nginx configuration file:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
include fastcgi_params;
}
Almost the website loads because the location of / is also set to /var/www on this config file.
location / {
root /var/www;
index index.php index.html index.htm;
}
When I use phpinfo() and read PHP variables table, I noticed this:
_SERVER["DOCUMENT_ROOT"] /usr/share/nginx/html
Other variables (most of them configured in nginx.conf)as server name, script filename, etc, were sent to php. So, nginx doesn't sending this variable to PHP.
What I have to do?
I'm using PHP 5.3.8 and nginx 0.8
Best Answer
$document_root is set by the root directive. The 'root html;' line in the php location sets $document_root to <nginx prefix>/html. Take a look at https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#root-inside-location-block to see how you should be setting your root in the server context. It should look something like this: