nginx - nginx 中的 fastcgi_index 是干什么用的?

标签 nginx fastcgi

在许多站点上都可以找到这个 nginx location堵塞 :

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

鉴于 official documentationfastcgi_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有用和使用:when nginx and php-fpm are on different servers and nginx can't match the index.php file .

关于nginx - nginx 中的 fastcgi_index 是干什么用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30802025/

相关文章:

php - FastCGI 进程最近经常失败 - 对于 IIS 7.5 上的 WP

docker - 让我们在 nginx docker 容器中加密

perl - 我如何从运行 FCGI.pm 的 Perl 脚本中获取错误以显示在 Apache 错误日志中?

django - 用于 django 应用程序的 nginx + FastCGI——运行两个还是一个 Web 服务器?

docker - Docker-拒绝使用Nginx连接到套接字的权限

apache - 以安全的方式创建每个用户的 php5-fpm 池

python - 从 nginx 传递到 uwsgi 的客户端连接 ID

angular - Nginx网址重写仅适用于/

nginx - nginx.conf 中的 log_format 被忽略

django - socks 的 Gunicorn 和 Django 错误权限被拒绝