Handling an error after X-Accel-Redirect

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

Handling an error after X-Accel-Redirect

Brian Moran-2
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?


Reply | Threaded
Open this post in threaded view
|

Re: Handling an error after X-Accel-Redirect

Maxim Dounin
Hello!

On Mon, Jun 01, 2009 at 04:32:05PM -0700, Brian Moran 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 Dounin