问题描述
我将Apache(在Debian上为2.2.22)配置为通过FastCGI处理PHP文件:
I have Apache (2.2.22 on Debian) configured to handle PHP files via FastCGI:
SetHandler应用程序/x-httpd-php
SetHandler application/x-httpd-php
</FilesMatch>
</FilesMatch>
动作应用程序/x-httpd-php/fcgi-bin/php5-fpm虚拟别名
Action application/x-httpd-php /fcgi-bin/php5-fpm virtual Alias
/fcgi-bin/php5-fpm/fcgi-bin-php5-fpm FastCgiExternalServer
/fcgi-bin/php5-fpm /fcgi-bin-php5-fpm FastCgiExternalServer
/fcgi-bin-php5-fpm -socket/var/run/php5-fpm.sock-空闲超时600 -pass-header授权
/fcgi-bin-php5-fpm -socket /var/run/php5-fpm.sock -idle-timeout 600 -pass-header Authorization
要显示自定义的找不到文件(HTTP 404)"页面,请在Apache中对其进行如下配置:
To show a custom File Not Found (HTTP 404) page is configured in Apache as follows:
..
ErrorDocument 404/pagenotfound.htm
ErrorDocument 404 /pagenotfound.htm
..
</目录>
对不存在的非PHP文件的请求将通过自定义404 pagenotfound.htm文件得到答复.没问题.
Requests for non-existing non-PHP files are answered with the custom 404 pagenotfound.htm file. No problem.
但是对不存在的PHP文件的请求将通过http-status-header"HTTP/1.1 404 Not Found"和内容"File not found."得到答复,因此不是我的自定义错误页面.问题!
But requests for non-existing PHP files are answered with http-status-header "HTTP/1.1 404 Not Found" and contents "File not found.", so not my custom error page. Problem!
Apache错误日志显示(在后一种情况下):
The Apache error log shows (in the latter case):
使用PHP-FPM时如何为不存在的PHP文件配置自定义404页面?
How can I configure a custom 404 page for non-existing PHP files when using PHP-FPM?
推荐答案
在全局服务器配置或单个虚拟主机中设置"ProxyErrorOverride on",请参见 http://httpd.apache.org/docs/current/mod/mod_modoxy.html#proxyerroroverride
set "ProxyErrorOverride on" in either your global server config or in individual virtual hosts, see http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxyerroroverride
这篇关于在Apache上使用PHP-FPM时的自定义404消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!