大网数据广告活动
服务器运维问答

Nginx $document_root$fastcgi_script_name vs $request_filename

· 52CE 我爱测

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 bette…

问题原文

原帖链接 · MultiformeIngegno · CC BY-SA 3.0

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.

已采纳解答

原帖链接 · SimonSimCity · CC BY-SA 4.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-01-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。