Forum: NGINX Handling an error after X-Accel-Redirect

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Brian M. (Guest)
on 2009-06-02 03:38
(Received via mailing list)
We'd like to be able to handle (perhaps try another server) an error
coming back after X-Accel-Redirect. In other words, the server to which
we redirected sends us a 500 -- we want to handle that error, or try
another server. Is this possible?
Maxim D. (Guest)
on 2009-06-02 07:45
(Received via mailing list)
Hello!

On Mon, Jun 01, 2009 at 04:32:05PM -0700, Brian M. wrote:

> We'd like to be able to handle (perhaps try another server) an error
> coming back after X-Accel-Redirect. In other words, the server to which
> we redirected sends us a 500 -- we want to handle that error, or try
> another server. Is this possible?

There are two possible approaches for fallback to another
server(s):

1. Use upstream{} with multiple servers defined and
proxy_next_upstream configured appropriately.

2. Use proxy_intercept_errors and set error_page, something like
this:

    location /files/ {
        proxy_intercept_errors on;
        error_page 500 = @fallback;
        proxy_pass ...;
    }

    location @fallback {
        # try another server here
        proxy_pass ...;
    }

See wiki & docs for details.

Maxim D.
This topic is locked and can not be replied to.