nginx中的fastcgi_index有什么作用? [英] What is fastcgi_index in nginx used for?
问题描述
在许多站点上都可以找到此nginx location
块:
On many sites can be found this nginx location
block :
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000
fastcgi_index index.php
...
}
鉴于fastcgi_index
的官方文档,当请求以/
结尾时使用.但是,它与上面的location
块的正则表达式不匹配吗?我是否缺少有关fastcgi_index
指令的内容?
Given the official documentation of fastcgi_index
, it seems like it is used when requests end with /
. However, it doesn't match the regular expression of the location
block above? Am I missing something about the fastcgi_index
directive?
推荐答案
是的,如果您的nginx配置(在location
指令之外)没有index
指令,则location
指令将永远不匹配,并且fastcgi_index
指令没有用.
You are right, if your nginx configuration (outside the location
directive) has no index
directive, then the location
directive will never match and the fastcgi_index
directive is useless.
如果您的配置中有这样的一行
If you have a line like this on your configuration
index index.php
然后对/
的请求将创建对/index.php
的内部重定向,location
将匹配并且将调用fastcgi. php-fpm将需要一个SCRIPT_FILENAME
参数,该参数指向正在执行的文件.通常,配置看起来像这样:
then a request to /
will create an internal redirect to /index.php
, the location
will match and fastcgi will be called. php-fpm will need a SCRIPT_FILENAME
parameter that points to the file being executed. Normally, the configuration looks something like this:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
$fastcgi_script_name
包含匹配脚本的名称,因此fastcgi_index
被忽略.
$fastcgi_script_name
contains the name of the matched script, so fastcgi_index
is ignored.
There is at least one instance where fastcgi_index
is useful and used: when nginx and php-fpm are on different servers and nginx can't match the index.php file.
这篇关于nginx中的fastcgi_index有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!