# Error\_page directive, how does context affect error handling behavior?

**URL:** <https://www.ruby-forum.com/t/error-page-directive-how-does-context-affect-error-handling-behavior/217272>\
**Category:** NGINX\
**Created:** [February 26, 2012, 7:49pm UTC](https://www.ruby-forum.com/t/error-page-directive-how-does-context-affect-error-handling-behavior/217272 "2012-02-26T19:49:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 26, 2012, 7:49pm UTC](https://www.ruby-forum.com/t/error-page-directive-how-does-context-affect-error-handling-behavior/217272/1 "2012-02-26T19:49:18Z")

</div>

Hello,

I’m using nginx 1.1.14 on Debian Squeeze.

In /etc/nginx.conf I wrote:  
error\_page 404 [http://google.com](http://google.com);

That error\_page directive is written in the http context.

So far so good, when I visit [http://mydomain.com/foo.txt](http://mydomain.com/foo.txt) and foo.txt  
doesn’t exist in root’s folder, I’m getting redirected to  
[http://google.com](http://google.com) as  
per the 404 error handling.

However, if in my server context, inside /etc/sites-available/default, I  
write:  
error\_page 418 [http://nginx.org](http://nginx.org);

Then 404 error handling from http’s context doesn’t work anymore. When I  
visit [http://mydomain.com/foo.txt](http://mydomain.com/foo.txt) I’m not redirected to  
[http://google.com](http://google.com) as  
before but I see nginx’s default 404 error page “404 Not found”.

here is my nginx.conf: [nginx.conf - Pastebin.com](http://pastebin.com/5nffYFvK)  
and my default site conf: [sites-available/default - Pastebin.com](http://pastebin.com/CYcEFnwx)

Is there something I overlooked about nginx’s error\_page directive?

Thank you in advance for any help.  
Gregory

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 27, 2012, 4:19pm UTC](https://www.ruby-forum.com/t/error-page-directive-how-does-context-affect-error-handling-behavior/217272/2 "2012-02-27T16:19:41Z")

</div>

26 февраля 2012, 22:49 от Grégory Pakosz : \> Hello, \> \> I’m using nginx  
1.1.14 on Debian Squeeze. \> \> In /etc/nginx.conf I wrote: \> error\_page  
404 [http://google.com](http://google.com); \> \> That error\_page directive is written in the  
http context. \> \> So far so good, when I visit  
[http://mydomain.com/foo.txt](http://mydomain.com/foo.txt) and foo.txt \> doesn’t exist in root’s  
folder, I’m getting redirected to [http://google.com](http://google.com) as \> per the 404  
error handling. \> \> However, if in my server context, inside  
/etc/sites-available/default, I \> write: \> error\_page 418  
[http://nginx.org](http://nginx.org); \> \> Then 404 error handling from http’s context  
doesn’t work anymore. When I \> visit [http://mydomain.com/foo.txt](http://mydomain.com/foo.txt) I’m not  
redirected to [http://google.com](http://google.com) as \> before but I see nginx’s default  
404 error page “404 Not found”. \> \> here is my nginx.conf:  
[nginx.conf - Pastebin.com](http://pastebin.com/5nffYFvK) \> and my default site conf:  
[sites-available/default - Pastebin.com](http://pastebin.com/CYcEFnwx) \> \> Is there something I overlooked about  
nginx’s error\_page directive? The error\_page directives are inherited if  
and only if there is absolutely NO error\_page directive on the current  
level. Moreover, whenever you use the error\_page directive you are doing  
two things: 1) explicitly setting error pages for the specified error  
codes 2) implicitly resetting error pages for all the other error codes  
that are not explicitly set on the current level to their default values  
So your “error\_page 418 [http://nginx.org](http://nginx.org);” directive not only set the  
error page for error code 418, but also reset the error pages for error  
code 404 and all the other error codes to their default values. Max

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 27, 2012, 4:21pm UTC](https://www.ruby-forum.com/t/error-page-directive-how-does-context-affect-error-handling-behavior/217272/3 "2012-02-27T16:21:33Z")

</div>

> Hi Max,

Thank you for your answer. May I suggest that explanation enters the  
wiki  
in the error\_page directive section?

Gregory

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 27, 2012, 4:32pm UTC](https://www.ruby-forum.com/t/error-page-directive-how-does-context-affect-error-handling-behavior/217272/4 "2012-02-27T16:32:44Z")

</div>

Hello!

On Mon, Feb 27, 2012 at 03:19:38PM +0100, Grégory Pakosz wrote:

> > Hi Max,
> 
> Thank you for your answer. May I suggest that explanation enters the wiki  
> in the error\_page directive section?

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page)**
>
> This directive appeared in version 1.11.8.

: These directives are inherited from the previous level if and  
: only if there are no error\_page directives on the current level.

Maxim D.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 28, 2012, 4:53am UTC](https://www.ruby-forum.com/t/error-page-directive-how-does-context-affect-error-handling-behavior/217272/5 "2012-02-28T04:53:54Z")

</div>

27 февраля 2012, 20:07 от Grégory Pakosz : \> \> \> \> \> \> Thank you for  
your answer. May I suggest that explanation enters the wiki \> \> \> in the  
error\_page directive section? \> \> \> \>  
[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page) \> \> \>

> : These directives are inherited from the previous level if and \> \> :  
> only if there are no error\_page directives on the current level. \> \> \> \>  
> Fair enough! \> \> I’ll refer to the doc more often then 🙂 \> \> Thank you  
> for the help You’re welcome. Maxim is right, this is documented, but the  
> implicit reset is not mentioned, so I’ve updated the wiki to make that  
> clear: [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#error_page) Max

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 27, 2012, 5:07pm UTC](https://www.ruby-forum.com/t/error-page-directive-how-does-context-affect-error-handling-behavior/217272/6 "2012-02-27T17:07:31Z")

</div>

> Fair enough!

I’ll refer to the doc more often then 🙂

Thank you for the help  
Gregory

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 28, 2012, 10:03am UTC](https://www.ruby-forum.com/t/error-page-directive-how-does-context-affect-error-handling-behavior/217272/7 "2012-02-28T10:03:20Z")

</div>

Hello!

On Tue, Feb 28, 2012 at 07:53:23AM +0400, Max wrote:

> 27 февраля 2012, 20:07 от Grégory Pakosz : \> \> \> \> \> \> Thank you for your  
> answer. May I suggest that explanation enters the wiki \> \> \> in the error\_page  
> directive section? \> \> \> \>  
> [Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page) \> \> \> \> : These  
> directives are inherited from the previous level if and \> \> : only if there are no  
> error\_page directives on the current level. \> \> \> \> Fair enough! \> \> I’ll refer to  
> the doc more often then 🙂 \> \> Thank you for the help You’re welcome. Maxim is  
> right, this is documented, but the implicit reset is not mentioned, so I’ve  
> updated the wiki to make that clear:  
> [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#error_page) Max

There is no “implicit reset”, it’s just a result of no  
inheritance. I don’t think that such a detailed explanation of  
how inheritance work is a good idea in context of error\_page  
directive documentation.

If you think this often causes serious misunderstanding, you may  
want to place the detail description somewhere at  
[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/Pitfalls), metioning various array-type  
directives which follow the same logic.

Maxim D.

p.s. You may want to avoid posting html to the list, especially  
keeping in mind that text parts of your html messages are hardly  
readable due to no line breaks.
