许多网站都可以找到这样的 nginx location
块:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000
fastcgi_index index.php
...
}
根据fastcgi_index的官方文档,它似乎是在请求以/
结尾时使用。但是,它与上面的location
块的正则表达式不匹配?我是否忽略了有关fastcgi_index
指令的某些内容?
许多网站都可以找到这样的 nginx location
块:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000
fastcgi_index index.php
...
}
根据fastcgi_index的官方文档,它似乎是在请求以/
结尾时使用。但是,它与上面的location
块的正则表达式不匹配?我是否忽略了有关fastcgi_index
指令的某些内容?
如果您的nginx配置(位于location
指令之外)没有index
指令,则location
指令将永远不会匹配,fastcgi_index
指令也就无用了。
如果在您的配置中有以下行:
index index.php
访问/
会内部重定向到/index.php
,匹配到location
后fastcgi将被调用。php-fpm需要一个指向正在执行文件的SCRIPT_FILENAME
参数。通常,配置看起来像这样:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
$fastcgi_script_name
包含匹配的脚本名称,因此fastcgi_index
被忽略。
至少有一种情况下fastcgi_index
是有用并被使用的:当nginx和php-fpm在不同的服务器上且nginx无法匹配index.php文件时。