【发布时间】:2020-02-08 16:14:06
【问题描述】:
出于安全原因,我想将我的 php-fpm 服务 chroot 到 /var/www/html。我在 Apache 2.4.10 中有一个虚拟主机,看起来像这样:
<VirtualHost *:8080>
DocumentRoot /var/www/html
DirectoryIndex index.php index.html /index.php /index.html
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php7.3-fpm.sock|fcgi://localhost/"
</FilesMatch>
</VirtualHost>
我的问题是当我在 php-fpm 的 pool .conf 中设置 chroot = /var/www/html 时,从 Apache 发送的文件路径不正确(由于 DocumentRoot 它会将 SCRIPT_FILENAME 设置为 /var/www/html/index.php,当 php-fpm现在会期待/index.php)。我可以通过 AliasMatch \.php$ / 将我的 php 文件从 DocumentRoot 文件夹中取出来解决这个问题,但这会阻止 DirectoryIndex 工作,因为现在 Apache 将 /index.php 查找为索引文件,这不会不存在。我假设这可能也是非常糟糕的形式......
有没有办法解决这个问题?我知道 nginx 可以通过重写 SCRIPT_FILENAME 来解决这个问题,但这不是我的选择。我也知道我可以设置doc_root php.ini 选项,但我听说这可能是个问题,因为它会影响与php 中的脚本路径相关的$_SERVER 变量。
在相关说明中,不在 chroot 中运行 php-fpm 有多不安全? (我已将 open_basedir 设置为 /var/www/html)
【问题讨论】:
-
This answer 建议使用
ProxyPassMatch而不是FileMatch处理类似情况。请尝试一下。 -
感谢您的提示。实际上,我最初一直在使用
ProxyPassMatch运行,但无法让它工作,但看起来我当时可能遇到了一个单独的设置问题,因为它现在似乎对我有用。