Proxy Retry Logic

Maxim Dounin mdounin at
Thu Dec 23 02:38:41 MSK 2010


On Wed, Dec 22, 2010 at 02:26:56PM -0500, Sirsiwal, Umesh wrote:

> I am trying to write a module which uses a number of subrequests 
> to talk to backend servers. Combines the responses and sends 
> them back to the client. The communication with the backend 
> server is using HTTP and I am using proxy_pass for that.
> The peculiarity in our setup is that on failure-retry I need to 
> use a different URI than the original request. Current, proxy 
> reinit request does not regenerate request hence cannot be used 
> for the purpose. I tried using the error_page in the subrequest 
> location to point to a different location. But, it seems that 
> the error_page is not evaluated on subrequest. The only option I 
> can think of is for my module to detect error and issue a new 
> subrequest.

Fallback via error_page should work ok for subrequests.  It may be 
disabled from post_subrequest handler though: if you use it and 
return something like NGX_OK from there (i.e. not NGX_HTTP_...  
error), error_page handling won't be executed assuming you've 
handled problem yourself.

Take a look at ngx_http_finalize_request(), it's more or less 
clear how it works.  Relevant parts are:

    if (r != r->main && r->post_subrequest) {
        rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);
        || rc == NGX_HTTP_CREATED
        || rc == NGX_HTTP_NO_CONTENT)
        ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));

(ngx_http_special_response_handler() is where actual error_page handling

Maxim Dounin

More information about the nginx-devel mailing list