# Fastcgi\_intercept\_errors & error\_page

**URL:** <https://www.ruby-forum.com/t/fastcgi-intercept-errors-error-page/224257>\
**Category:** NGINX\
**Created:** [November 5, 2012, 6:12pm UTC](https://www.ruby-forum.com/t/fastcgi-intercept-errors-error-page/224257 "2012-11-05T18:12:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 5, 2012, 6:12pm UTC](https://www.ruby-forum.com/t/fastcgi-intercept-errors-error-page/224257/1 "2012-11-05T18:12:57Z")

</div>

According to the doc:  
[http://wiki.nginx.org/HttpFastcgiModule#fastcgi\_intercept\_errors](http://wiki.nginx.org/HttpFastcgiModule#fastcgi_intercept_errors)

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.”

Actually I still can’t understand the exact meaning, so I have done some  
experimentd.

1. turn on fastcgi\_intercept\_errors,
  - in the backend php/fcgi send 404 header,
  - set the error\_page (php)

Result: nginx use the default error template

1. turn off fastcgi\_intercept\_errors,
  - in the backend php/fcgi send 404 header
  - set the error\_page (php)

Result: now the custom error\_page (php) is being used.

So it seems to me that\* fastcgi\_intercept\_errors should be off and set  
the error\_page \*if I need to specify custom error handler, is  
this interoperation correct?

Thanks.

---

<div class="post-metadata">

**Author:** ![howard\_chen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bbce88/32.png) [@howard\_chen](https://www.ruby-forum.com/u/howard_chen)\
**Post date:** [November 9, 2012, 4:34am UTC](https://www.ruby-forum.com/t/fastcgi-intercept-errors-error-page/224257/2 "2012-11-09T04:34:46Z")

</div>

Hello!

On Tue, Nov 06, 2012 at 01:12:05AM +0800, howard chen wrote:

> Result: now the custom error\_page (php) is being used.  
> It’s unclear how you did your experiments, but results  
> are all wrong - most likely, you missed something.

E.g. in (1) I would assume request to the error\_page resulted in  
another 404, which in turn resulted in default error page  
returned.

> So it seems to me that\* fastcgi\_intercept\_errors should be off and set  
> the error\_page \*if I need to specify custom error handler, is  
> this interoperation correct?

No.

The fastcgi\_intercept\_errors directive is off by default, and this  
means that nginx won’t try to do anything with responses returned  
by backends as long as they are valid.

If you want nginx to change response returned by a backend, you  
have to switch on fastcgi\_intercept\_errors and configure  
appropriate error\_page. Example configuration:

```
error_page 404 /errors/404.html;

location / {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_intercept_errors on;
    ...
}

location /errors/ {
    # static
}

```

With the above config if fastcgi backend returns 404, the  
/errors/404.html will be returned instead (assuming it exists).

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.
