什么是nginx中的fastcgi_index用于?

时间:2015-06-12 11:31:48

标签: nginx fastcgi

在许多网站上都可以找到这个nginx location块:

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000
    fastcgi_index index.php
    ...
}

鉴于fastcgi_index的{​​{3}},似乎在请求以/结尾时使用。但是,它与上面的location块的正则表达式不匹配?我错过了关于fastcgi_index指令的内容吗?

1 个答案:

答案 0 :(得分:6)

你是对的,如果你的nginx配置(在location指令之外)没有index指令,那么location指令永远不会匹配,fastcgi_index指令是无用的。

如果您的配置中有这样的行

index index.php

然后,对/的请求将创建内部重定向到/index.phplocation将匹配,并且将调用fastcgi。 php-fpm需要一个SCRIPT_FILENAME参数来指向正在执行的文件。通常,配置看起来像这样:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

$fastcgi_script_name包含匹配脚本的名称,因此忽略fastcgi_index

至少有一个fastcgi_index有用且有用的实例:when nginx and php-fpm are on different servers and nginx can't match the index.php file

相关问题