Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is part of my nginx configuration file:

# pass the PHP scripts to FastCGI server listening on
location ~ \.php$ {
    root           html;
    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

share|improve this question
Move your 'root' directive outside the location blocks - it should be in the server block (and verify that you have a line reading fastcgi_param DOCUMENT_ROOT $document_root; in your fastcgi_parms file) – cyberx86 Oct 24 '11 at 21:17
It's already inside in the Default Server Block. – Mr_LinDowsMac Oct 24 '11 at 21:23
up vote 4 down vote accepted

$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 to see how you should be setting your root in the server context. It should look something like this:

server {
  root /var/www;
  index index.php index.html index.htm;

  location ~ \.php$ {
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
share|improve this answer

I'm using nginx 1.0.6, and this is in my fastcgi_params:

fastcgi_param  DOCUMENT_ROOT      $document_root;

Not sure if this will help you on 0.8, but updating nginx will help if not.

share|improve this answer
Not really, it's the same in nginx 0.8 – Mr_LinDowsMac Oct 24 '11 at 21:22
@ianenri: It works perfectly on 1.0. Could be a bug in 0.8 then. Still, this is how you set it. You could set it manually rather than via the variable, that should solve your issue. – Matthew Scharley Oct 24 '11 at 21:25
And where I should set this $document_root variable? – Mr_LinDowsMac Oct 24 '11 at 21:40
@ianenri: I'd add a line to your location, directly after the include fastcgi_params that is something like fastcgi_param DOCUMENT_ROOT /var/www;. I doubt you can actually set $document_root. Also, look at kolbyjacks answer, as that's likely the root of the problem. – Matthew Scharley Oct 24 '11 at 22:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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