Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

$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 {
  time();
}';

# where you want it:
proxy_set_header X-Start-Time $unix_timestamp;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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