nginx中的fastcgi_index有什么作用? [英] What is fastcgi_index in nginx used for?

查看:126
本文介绍了nginx中的fastcgi_index有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多站点上都可以找到此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.

至少有一个实例可以使用和使用fastcgi_index:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆