Custom 404 message when using PHP-FPM with Apache

醉酒当歌 提交于 2019-12-12 11:26:48

问题


I have Apache (2.2.22 on Debian) configured to handle PHP files via FastCGI:

<FilesMatch ".+.php$">

SetHandler application/x-httpd-php

</FilesMatch>

Action application/x-httpd-php /fcgi-bin/php5-fpm virtual Alias

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

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

To show a custom File Not Found (HTTP 404) page is configured in Apache as follows:

<Directory "/home/http/domain/root">

..

ErrorDocument 404 /pagenotfound.htm

..

</Directory>

Requests for non-existing non-PHP files are answered with the custom 404 pagenotfound.htm file. No problem.

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!

The Apache error log shows (in the latter case):

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

How can I configure a custom 404 page for non-existing PHP files when using PHP-FPM?


回答1:


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



来源:https://stackoverflow.com/questions/33843786/custom-404-message-when-using-php-fpm-with-apache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!