Logging header values from the first upstream

Maxim Dounin mdounin at mdounin.ru
Thu Oct 10 22:56:01 UTC 2013


On Fri, Oct 11, 2013 at 12:27:34AM +0200, Matt Spitz wrote:

> The HttpUpstreamModule states that variable values for
> $upstream_http_$HEADER are only valid for the last upstream accessed
> during a request.  I'd like to know if there's a workaround.


The $upstream_* variables are cleared once nginx starts to work 
with a new upstream.  If you want to preserve values before 
X-Accel-Redirect, you may do so by using "set" in a destination 
location of X-Accel-Redirect (this works as rewrite directives are 
executed before upstream data is re-initialized).  E.g.:

    location /api/ {
        proxy_pass ...

    location /internal/ {
        set $previous_upstream_http_foo $upstream_http_foo;
        proxy_pass ...

Maxim Dounin

More information about the nginx mailing list