Apache2+php-fpm环境下含空格的DocumentRoot引发AH01071错误求助
Apache2+php-fpm环境下含空格的DocumentRoot引发AH01071错误求助
大家好,我最近碰到一个挺棘手的问题,想请教下社区的各位大佬:
我们的服务器跑的是Ubuntu 20.04.6 LTS,通过ppa:ondrej/php源安装了多个PHP版本。几周前,部分虚拟主机突然挂了,Apache直接抛出错误:"AH01071: Got error 'Primary script unknown'"。
折腾了半天排查出来,只有DocumentRoot路径带空格的虚拟主机才会出这个问题。下面是我做的两个测试场景:
场景1:无空格路径 + php-fpm(完全正常)
这个虚拟主机的DocumentRoot没有空格,搭配php-fpm的配置运行毫无问题:
<VirtualHost *:80> ServerName test.mydomain.com DocumentRoot "/var/www/directory" <Directory "/var/www/directory"> AllowOverride All Require all granted </Directory> <FilesMatch ".+\.ph(ar|p|tml)$"> SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost" </FilesMatch> </VirtualHost>
场景2:带空格路径 + 不使用php-fpm(正常工作)
如果给带空格的路径配置虚拟主机,但不启用php-fpm相关的处理规则,网站也能正常运行:
<VirtualHost *:80> ServerName test-space.mydomain.com DocumentRoot "/var/www/directory with spaces" <Directory "/var/www/directory with spaces"> AllowOverride All Require all granted </Directory> # 未配置php-fpm的SetHandler,使用Apache自带的PHP处理模块(如mod_php) </VirtualHost>
但只要给带空格的DocumentRoot加上php-fpm的SetHandler配置,就会立刻触发开头提到的AH01071错误。有没有人遇到过类似的问题?或者知道该怎么调整配置,才能让php-fpm正常处理带空格的DocumentRoot路径?
备注:内容来源于stack exchange,提问作者Martin Wolfgang
相关产品推荐
相关产品推荐

