Welcome! Log In Create A New Profile

Advanced

Logging header values from the first upstream

Matt Spitz
October 10, 2013 06:28PM
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.

Specifically, I'm setting (and then clearing) headers in my first
upstream to get request-specific information like 'username'. Here's
what I've got:

===

http {
log_format myapp '$remote_addr [$time_local] '
'$request_time '
'"$request" $status '
'$request_length $body_bytes_sent '
'"$upstream_addr" $upstream_response_time'
'$upstream_http_x_myapp_username ';
...

server {
location /api/ {
...
access_log /var/log/nginx/myapp_access.log myapp;

proxy_pass http://myapp_upstream;

more_clear_headers 'X-MyApp-Username';
...
}

location ~* /internal/media_url/(.*) {
# only allowed for internal redirects (X-Accel-Redirect,
included)
internal;

# still need to set our access log to get the original
request
access_log /var/log/nginx/myapp_access.log myapp;

proxy_pass $1;
}
}
}

===

Some of my /api accesses result in internal media redirects, so I use
the X-Accel-Redirect header to redirect to an internal location.
Obviously, when the first location redirects to /internal/media_url/*,
the reference to $upstream_http_x_myapp_username in my log line refers
to the X-MyApp-Username header that is returned by the media server,
which is empty.

How can I log the username with my requests that result in an internal
redirect when the information is only available from the first upstream?

Thanks for your help!

--
Posted via http://www.ruby-forum.com/.

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Logging header values from the first upstream

Matt Spitz October 10, 2013 06:28PM

Re: Logging header values from the first upstream

Maxim Dounin October 10, 2013 06:58PM

Re: Logging header values from the first upstream

Matt Spitz October 10, 2013 11:34PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 300
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready