Wrong values for $upstream_response_time in add_header?

Hi,

I’m cross-posting this from the forums to the mailinglist in hope for
getting a reply here. Sorry for that.

I’m using nginx-1.2.0 (plus upstream-fair and headers-more; for
complete nginx -V and uname -a please see
nginx -V · GitHub) and I’m really happy
with that. However I want to add a couple of Headers
($upstream_response_time in this case) to be passed to the Client for
debugging purposes. So I’ve added add_header X-AppServer-Response $upstream_response_time; to my location block where I do all my proxy
stuff. I’ve got an upstream block where I’ve put in my 3 backend
servers. All Backends respond very fast during testing.

However there are unreasonable high values within this header
(X-AppServer-Response: 74768.562 in this case). I’m using access_log
to get some more values written to disk as well for central
monitoring. Within this log all values seem to be ok (for this
particular request it’s 0.002 to be exact).

I was able to reproduce that behaviour using different backends
(apache2 and another nginx in this case).

Any Idea what’s going wrong here?

Regards,
Chris

Hello!

On Fri, May 04, 2012 at 10:19:49AM +0200, Christian Bönning wrote:

stuff. I’ve got an upstream block where I’ve put in my 3 backend

Any Idea what’s going wrong here?

The $upstream_response_time is only meaningful once response is
fully got from upstream, and this happens after response headers
are got (and sent to client). That is, you basically can’t use
$upstream_response_time in add_header, only in logs.

Maxim D.