Q:

Nginx $document_root$fastcgi_script_name vs $request_filename

I can't notice any difference if in my config file I set
 fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

Or:
 fastcgi_param  SCRIPT_FILENAME    $request_filename;

What do they do respectively?  Is one of the two better than the other? 
Thanks in advance. 

A:

Here's what the documentation says:
$request_filename

This variable is equal to path to the file for the current request, formed from directives root or alias and URI request;

$document_root

This variable is equal to the value of directive root for the current request; 

$fastcgi_script_name

This variable is equal to the URI request or, if if the URI concludes with a forward slash, then the URI request plus the name of the index file given by fastcgi_index.  It is possible to use this variable in place of both SCRIPT_FILENAME and PATH_TRANSLATED, utilized, in particular, for determining the name of the script in PHP. 

As written here, there's at least a difference when using fastcgi_index or fastcgi_split_path_info.  Maybe there are more ... that's what I know of right now. 
Example
You get the request /info/ and have the following configuration:
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /home/www/scripts/php$fastcgi_script_name;

SCRIPT_FILENAME would equal /home/www/scripts/php/info/index.php, but using $request_filename it would just be /home/www/scripts/php/info/.
The configuration of fastcgi_split_path_info is important as well.  See here for further help: http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_split_path_info

A:

TLDR
I recommended use $request_filename for SCRIPT_FILENAME. 

If you using root directive
$document_root$fastcgi_script_name is equal to $request_filename. 
If you using alias directive
$document_root$fastcgi_script_name will return the wrong path, because $fastcgi_script_name is path of the URL, not the path relate to $document_root. 
Example
If you have config
location /api/ {
    index  index.php index.html index.htm;
    alias /app/www/;
    location ~* "\.php$" {
        try_files      $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        # fastcgi_param  SCRIPT_FILENAME  $request_filename;
    }
}

Request /api/testing.php:

$document_root$fastcgi_script_name == /app/www//api/testing.php
$request_filename == /app/www/testing.php

Request /api/:

$document_root$fastcgi_script_name == /app/www//api/index.php
$request_filename == /app/www/index.php

And if you use $request_filename, you should set index using index directive, fastcgi_index will not work.