将 PHP-FPM 与 Apache 一起使用时的自定义 404 消息

cor*_*ret 5 php apache mod-fastcgi

我将 Apache(Debian 上的 2.2.22)配置为通过 FastCGI 处理 PHP 文件:

<FilesMatch ".+.php$">

SetHandler 应用程序/x-httpd-php

</文件匹配>

动作应用程序/x-httpd-php /fcgi-bin/php5-fpm 虚拟别名

/fcgi-bin/php5-fpm /fcgi-bin-php5-fpm FastCgiExternalServer

/fcgi-bin-php5-fpm -socket /var/run/php5-fpm.sock -idle-timeout 600 -pass-header 授权

显示自定义文件未找到 (HTTP 404) 页面在 Apache 中配置如下:

<目录“/home/http/domain/root”>

..

错误文档 404 /pagenotfound.htm

..

</目录>

使用自定义 404 pagenotfound.htm 文件回答对不存在的非 PHP 文件的请求。没问题。

但是对不存在的 PHP 文件的请求以 http-status-header“HTTP/1.1 404 Not Found”和内容“File not found.”回答,所以不是我的自定义错误页面。问题!

Apache 错误日志显示(在后一种情况下):

[Sat Nov 21 14:03:07 2015] [error] [client xx.xxx.xx.xx] FastCGI: server "/fcgi-bin-php5-fpm" stderr: Primary script unknown

使用 PHP-FPM 时如何为不存在的 PHP 文件配置自定义 404 页面?

Ala*_*les 5

在全局服务器配置或单个虚拟主机中设置“ProxyErrorOverride on”,请参阅http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxyerroroverride