title: Root path for 404 PHP page under nginx (php-fpm) doesn't work
body: <p>If I try to access anything unexisting in the site's root directory, i.e. <a href="http://example.com/unexisting.php" rel="nofollow">http://example.com/unexisting.php</a>, I get <strong>right</strong> good answer from my custom 404 page using the following config:</p>
  
  <pre><code>server_name example.com;
  root        /path/to/example;
  index       index.php;
  error_page 404  /not_found.php;
  
  location ~ index\.php
  {
      try_files $uri/index.php =404;
      return 301 $scheme://$server_name/;
  }
  
  location ~ not_found\.php
  {
      root        /path/to/example;
      allow all;
      internal;
      fastcgi_intercept_errors off;
      fastcgi_param SCRIPT_FILENAME $document_root/not_found.php;
      include fastcgi_params;
  }
  
  location = /
  {
      try_files $uri/index.php @static;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_param SCRIPT_FILENAME $document_root/index.php;
      include fastcgi_params;
  }
  
  location ~ \.php$
  {
      try_files $uri $uri/ =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_intercept_errors on;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
  }
  
  location @static
  {
      try_files $uri $uri/ =404;
      expires max;
  }
  
  location /
  {
      try_files /something_non_existing @static;
  }
  </code></pre>
  
  <p>If I try to access files out the root folder, i. e. "<a href="http://example.com/unexisting_dir/unexisting.php" rel="nofollow">http://example.com/unexisting_dir/unexisting.php</a>", the 404 page is on the screen, but without any graphics. Because in logs are things like "GET /unexisting_dir/images/some_image_for_404_page.png HTTP/1.1" and nginx returns nothing, 'cause it has a wrong base from the user request. Meanwhile, I've checked that $document_root has the right base, so php-fpm works perfect.</p>
  
  <p><strong>The question is how to make nginx ignore user's URI in case of servicing 404 page for unexisting nested (embedded) directories (without redirecting and harming anything potential) ?</strong></p>
  
  <p>Many thanks in advance!</p>
  
  <p>This is "fastcgi_params" (just in case):</p>
  
  <pre><code>    fastcgi_param  QUERY_STRING       $query_string;
      fastcgi_param  REQUEST_METHOD     $request_method;
      fastcgi_param  CONTENT_TYPE       $content_type;
      fastcgi_param  CONTENT_LENGTH     $content_length;
      fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
      fastcgi_param  REQUEST_URI        $request_uri;
      fastcgi_param  DOCUMENT_URI       $document_uri;
      fastcgi_param  DOCUMENT_ROOT      $document_root;
      fastcgi_param  SERVER_PROTOCOL    $server_protocol;
      fastcgi_param  HTTPS              $https if_not_empty;
      fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
      fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
      fastcgi_param  REMOTE_ADDR        $remote_addr;
      fastcgi_param  REMOTE_PORT        $remote_port;
      fastcgi_param  SERVER_ADDR        $server_addr;
      fastcgi_param  SERVER_PORT        $server_port;
      fastcgi_param  SERVER_NAME        $server_name;
      fastcgi_param  REDIRECT_STATUS    200;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
  </code></pre>