proxy_set_header variable evaluation

Arvind Jayaprakash work at
Wed Aug 26 22:34:33 MSD 2009

I am trying to do some tricks with upstream+proxy and ran into what
seems like a limitation of the proxy_set_header feature.

When an upstream's response triggers resending the request to the next
upsteam, I was hoping $upstream_response_time is available with data of
what happened in the previous upsteams. I'm trying to pass it using the
following directive:

proxy_set_header X-retry1 $upstream_response_time;

It looks like the variable is always unavailable (even when when nginx
tries to access the second upstream for the same request). However, the
value seems to be available during the logging phase.

I tried recompiling with the response variable marked as uncachable (v->no_cacheable = 1) but that did not seem to help.

The question is if this is a limitation of proxy_set_header or upstream
variables? I got a feeling that $upstream_response_time is evaluated
once before the upstreams are tried and evalutes to "not found" and not
re-evaluated for each upstream attempt.

More information about the nginx mailing list