Handling an error after X-Accel-Redirect

Maxim Dounin mdounin at mdounin.ru
Tue Jun 2 07:39:45 MSD 2009


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 

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

2. Use proxy_intercept_errors and set error_page, something like 

    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

More information about the nginx mailing list