Strange error_page behavior

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange error_page behavior

Fabiano Furtado Pessoa Coelho
Hi...

I have the following setup in my NGINX 1.18.0 server:

http {
  ...
  error_page 400     /my400.html;
  error_page 401     /my401.html;
  error_page 403     /my403.html;
  error_page 404     /my404.html;
  error_page 405     /my405.html;
  error_page 413     /my413.html;
  error_page 500     /my500.html;
  error_page 502 503 /my503.html;
  error_page 504     /my504.html;
  ...
  server {
    ...
    allow 10.0.0.0/8; # my internal network
    deny all;         # all others networks

    error_page 403 =503 /my503.html;
    #error_page 502 503  /my503.html;

    location ~ ^/(my400|my401|my403|my404|my405|my413|my500|my503|my504)\.html$
{
      root /usr/share/nginx/my_custom_error_pages;
      internal;
      allow all;
    }
    ...
    location / {
      ...
      proxy_pass http://...;
    }
  }
}


In this setup, I want to allow my internal network to access my
backend server via proxy_pass AND deny this access to others networks
(error 403 "redirected" to 503 --> defined in "error_page 403 =503
/my503.html;").
This is working great, but when my backend gets down, I receive a
default NGINX "502 Bad Gateway" error page instead of my custom
my503.html page.
Why this is happening?
I can solve this issue uncommenting the "#error_page 502 503
/my503.html;" line in server block, but this configuration is already
defined in http block, which is hierarchically superior in comparison
with server block. Why NGINX isn't regarging the error_page in http
block?

Thanks in advance.
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Strange error_page behavior

Francis Daly
On Thu, Aug 06, 2020 at 09:43:46PM -0300, Fabiano Furtado Pessoa Coelho wrote:

Hi there,

> http {
>   error_page 502 503 /my503.html;
>   ...
>   server {
>     ...
>     error_page 403 =503 /my503.html;
>     #error_page 502 503  /my503.html;

> I can solve this issue uncommenting the "#error_page 502 503
> /my503.html;" line in server block, but this configuration is already
> defined in http block, which is hierarchically superior in comparison
> with server block. Why NGINX isn't regarging the error_page in http
> block?

Nginx directive inheritance is (in general) "by replacement" or "not
at all".

If you have a directive in a location, that is the full set of
that-directives that applies to the matching request.

Since you have an error_page at server{} level, any error_page defined
at http level is irrelevant for any request handled in this server{}.

http://nginx.org/r/error_page

If you want a distinct set of error_page directives to apply at
server{}-level, you must write them all there (perhaps by "include"ing
a file).

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Strange error_page behavior

Fabiano Furtado Pessoa Coelho
Thanks for the reply and I'm sorry! It was my fault that I didn't see
that text in the documentation.

"These directives are inherited from the previous level if and only if
there are no error_page directives defined on the current level."

On Fri, Aug 7, 2020 at 4:05 AM Francis Daly <[hidden email]> wrote:

>
> On Thu, Aug 06, 2020 at 09:43:46PM -0300, Fabiano Furtado Pessoa Coelho wrote:
>
> Hi there,
>
> > http {
> >   error_page 502 503 /my503.html;
> >   ...
> >   server {
> >     ...
> >     error_page 403 =503 /my503.html;
> >     #error_page 502 503  /my503.html;
>
> > I can solve this issue uncommenting the "#error_page 502 503
> > /my503.html;" line in server block, but this configuration is already
> > defined in http block, which is hierarchically superior in comparison
> > with server block. Why NGINX isn't regarging the error_page in http
> > block?
>
> Nginx directive inheritance is (in general) "by replacement" or "not
> at all".
>
> If you have a directive in a location, that is the full set of
> that-directives that applies to the matching request.
>
> Since you have an error_page at server{} level, any error_page defined
> at http level is irrelevant for any request handled in this server{}.
>
> http://nginx.org/r/error_page
>
> If you want a distinct set of error_page directives to apply at
> server{}-level, you must write them all there (perhaps by "include"ing
> a file).
>
>         f
> --
> Francis Daly        [hidden email]
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx