nginx php页面 error_page 404不起作用解决

普通静态文件如果不存在是正在返回指定的404页面的,但是php页面不行,
我看了下配置

error_page 404 /error.html;
完全没问题,初步估计是fastcgi没把错误给Nginx
查了下nginx的文档 果然

fastcgi_intercept_errors
syntax: fastcgi_intercept_errors on|off

default: fastcgi_intercept_errors off

context: http, server, location

This directive determines whether or not to transfer 4xx and 5xx errors back to the client or to allow Nginx to answer with directive error_page.
Note: You need to explicitly define the error_page handler for this for it to be useful. As Igor says, "nginx does not intercept an error if there is no custom handler for it it does not show its default pages. This allows to intercept some errors, while passing others as are."

只需在虚拟主机配置文件加入:

fastcgi_intercept_errors on;
即可

nginx php页面 error_page 404不起作用解决