Skip to main content
 首页 » 编程设计

php之ProxyPassMatch 和选项+索引 (mod_autoindex)

2024年05月10日31jillzhang

我使用 Apache2.4 和 PHP-FPM 进行了简单的设置,并且尝试启用 +Indexes 选项,但收到 404“找不到文件”。当尝试访问没有索引文件的文件夹时,即使启用了自动索引。

这是我的虚拟主机的一部分:

#php 
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/var/run/fpm/fatal.sock|fcgi:// 
 
#super public directory with Indexes! 
<Location /pub> 
    Options +Indexes 
    IndexOptions +FancyIndexing 
</Location> 

当我尝试访问http://domain.com/pub/时我希望看到我放在那里的文件列表,但我收到错误 404 Not Found。

我想知道这是从哪里来的,因为 ProxyPassMatch 不应该转发请求,因为查询中没有 .php,所以接下来是目录索引,它查找不存在的 index.php (404) 但为什么 mod_autoindex 不存在不工作吗?

当我删除 ProxyPassMatch 行时,自动索引工作正常,并且我看到列出的文件夹内容。 有什么想法吗?

请您参考如下方法:

我在这里找到了答案http://blog.famillecollet.com/post/2014/03/28/PHP-FPM-and-HTTPD-2.4-improvement

As the ProxyPassMatch directive is evaluated at the very beginning of each request:

  • AddType (for MultiView) or DirectoryIndex directives are not usable

  • right management per directory is not available

  • each Alias directive needs another proxy rule

The SetHandler directive, evaluated later, is much more flexible / usable.

所以我将我的虚拟主机更改为如下所示,并摆脱了 ProxyPassMatch 指令。

<FilesMatch \.php$> 
  SetHandler "proxy:unix:/var/run/fpm/fatal.sock|fcgi://" 
</FilesMatch> 

注意:此解决方案适用于 Apache 2.4.9+

(我确实想知道是否有任何性能差异以及在什么方向?)