I'd like to have my Nginx load balancer send a timestamp in a header onto the upstream servers.

I tried something like this:

proxy_set_header X-Start-Time $msec;

Of course, $msec is a log variable and Nginx gives an error:

Restarting nginx: [emerg]: unknown "msec" variable

$msec is indeed a variable that lives only during log writing.

The easiest solution would be to build Nginx with Perl module and define a variable backed by Perl subroutine:

# at 'http' context
perl_set $unix_timestamp 'sub {

# where you want it:
proxy_set_header X-Start-Time $unix_timestamp;

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.