Sal Rahman
Sal Rahman

Reputation: 4755

Is there a way to get the current time in nginx?

I am trying to inject the time of an nginx server into an HTTP header.

I am able to add to an HTTP header, like so:

proxy_set_header HELLO-WORLD 'something';

But now, I want to be able to inject the time into an HTTP header, something that looks like this:

proxy_set_header THE-TIME $time_var;

Or something like that.

Would that be possible?

Upvotes: 13

Views: 29465

Answers (2)

Alex
Alex

Reputation: 8493

$time_iso8601 is both machine- & human-friendly.

Upvotes: 5

VBart
VBart

Reputation: 15110

You can use variables from SSI modulе: $date_gmt and $date_local

proxy_set_header THE-TIME $date_gmt;

http://nginx.org/en/docs/http/ngx_http_ssi_module.html#variables

Upvotes: 16

Related Questions