# Nested error\_page

**URL:** <https://www.ruby-forum.com/t/nested-error-page/200514>\
**Category:** NGINX\
**Created:** [December 14, 2010, 8:08am UTC](https://www.ruby-forum.com/t/nested-error-page/200514 "2010-12-14T08:08:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 14, 2010, 8:08am UTC](https://www.ruby-forum.com/t/nested-error-page/200514/1 "2010-12-14T08:08:04Z")

</div>

hi

i have a situtation where i would need something similar to this:

location / {  
error\_page 404 = /fallback\_all;  
// do a request to get content from memcache, if not found go to  
/fallback\_all  
}

location = /fallback\_all {  
internal;  
error\_page 404 = @404;  
// do a request to get content from fastcgi, if not found go to @404  
}

location @404 {  
internal;  
// real 404 page  
}

but this doesn’t work. if the fastcgi returns a 404 then nginx will  
just display its own error page and ignore the second error\_page  
directive. i’m guessing that the reason is that at the first 404 error  
it already sets the ngx\_http\_request\_t-\>err\_status to something which  
makes it ignore the second 404.

is there any way around this? i could probably make the fastcgi return  
some other code, but i’m also not sure if this will make it work then.  
is there any directive which could make the second error\_page work?  
something to allow nested error\_pages

thanks,

mauro

---

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [December 14, 2010, 8:20am UTC](https://www.ruby-forum.com/t/nested-error-page/200514/2 "2010-12-14T08:20:00Z")

</div>

great, that works, thanks!

---

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [December 14, 2010, 8:13am UTC](https://www.ruby-forum.com/t/nested-error-page/200514/3 "2010-12-14T08:13:44Z")

</div>

On Tue, Dec 14, 2010 at 03:07:08PM +0800, Mauro Stettler wrote:

> internal;  
> error\_page 404 = @404;  
> // do a request to get content from fastcgi, if not found go to @404

```
recursive_error_pages on;

```

> it already sets the ngx\_http\_request\_t-\>err\_status to something which  
> makes it ignore the second 404.
> 
> is there any way around this? i could probably make the fastcgi return  
> some other code, but i’m also not sure if this will make it work then.  
> is there any directive which could make the second error\_page work?  
> something to allow nested error\_pages

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [December 14, 2010, 12:49pm UTC](https://www.ruby-forum.com/t/nested-error-page/200514/4 "2010-12-14T12:49:58Z")

</div>

Hello!

On Tue, Dec 14, 2010 at 10:12:38AM +0300, Igor S. wrote:

> On Tue, Dec 14, 2010 at 03:07:08PM +0800, Mauro Stettler wrote:
> 
> > i have a situtation where i would need something similar to this:
> > 
> > location / {  
> > error\_page 404 = /fallback\_all;  
> > // do a request to get content from memcache, if not found go to  
> > /fallback\_all

- 

```
recursive_error_pages on;

```

> > }
> > 
> > location = /fallback\_all {  
> > internal;  
> > error\_page 404 = @404;  
> > // do a request to get content from fastcgi, if not found go to @404
> 
> ```
> recursive_error_pages on;
> 
> ```

- 

```
recursive_error_pages on;

```

> > }
> > 
> > location @404 {  
> > internal;  
> > // real 404 page  
> > }

Directive “recursive\_error\_pages on;” should be specified in the  
location which generates initial error (and in subsequent ones  
which have error\_page set to “non-real” error pages), “location /”  
in this case.

Setting “recursive\_error\_pages on;” prevents nginx from setting  
the flag “we are in error handler” (r-\>error\_page) when going to  
error\_page. This flag prevents further error\_page processing. If  
it’s already set - recursive\_error\_pages does nothing.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [December 14, 2010, 12:58pm UTC](https://www.ruby-forum.com/t/nested-error-page/200514/5 "2010-12-14T12:58:47Z")

</div>

On Tue, Dec 14, 2010 at 02:49:03PM +0300, Maxim D. wrote:

> > > // do a request to get content from memcache, if not found go to  
> > > /fallback\_all  
> > > recursive\_error\_pages on;  
> > > Directive “recursive\_error\_pages on;” should be specified in the  
> > > location which generates initial error (and in subsequent ones  
> > > which have error\_page set to “non-real” error pages), “location /”  
> > > in this case.
> 
> Setting “recursive\_error\_pages on;” prevents nginx from setting  
> the flag “we are in error handler” (r-\>error\_page) when going to  
> error\_page. This flag prevents further error\_page processing. If  
> it’s already set - recursive\_error\_pages does nothing.

Yes, you are right: it should be set in locations that allow several  
error\_page handling.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
