Welcome! Log In Create A New Profile

Advanced

Re: Serving default error pages with 'proxy_intercept_errors on'

Maxim Dounin
December 28, 2013 07:22AM
Hello!

On Fri, Dec 27, 2013 at 03:47:51PM -0500, Maxim Khitrov wrote:

> Hello,
>
> I'm running nginx v1.4.1 on OpenBSD 5.4 and I'd like to use
> 'proxy_intercept_errors on' directive without providing my own error
> pages. In other words, instead of forwarding page content from the
> backend server, just use the error pages that nginx generates by
> default.
>
> This isn't supported normally, however the following configuration
> seems to achieve the desired result (though you have to list the error
> codes explicitly):
>
> error_page 403 404 ... @error;
> location @error { return 444; }
>
> I didn't actually know what this would do until I tried it. I assume
> that when a matching error code is received from the backend server,
> nginx closes the proxy connection without reading the body and creates
> a new internal request to @error, which is immediately closed without
> a response. Thus, there is no body to send to the client, so it falls
> back to the default behavior.

Not really.

What you see works because currently "return <4xx>" doesn't
override error code previously set, thus for 404 error code
originally returned by a proxied server

location @error { return 4xx; }

is effectively equivalent to

location @error { return 404; }

which is documented to return "status code of the last occurred
error", see http://nginx.org/r/error_page.

> The question is whether this behavior is an accident and may change in
> a future version, or if it's an acceptable way of intercepting errors
> without providing custom error pages?

I wouldn't recommend relaying on this. Current behaviour of
"return", which effectively uses previous error code set, is
somewhat questionable, and may change in the future.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Serving default error pages with 'proxy_intercept_errors on'

Maxim Khitrov December 27, 2013 03:50PM

Re: Serving default error pages with 'proxy_intercept_errors on'

Maxim Dounin December 28, 2013 07:22AM

Re: Serving default error pages with 'proxy_intercept_errors on'

Maxim Khitrov December 28, 2013 10:00AM

Re: Serving default error pages with 'proxy_intercept_errors on'

Maxim Dounin December 29, 2013 06:18PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 239
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready