Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 897
Sal Rahman Avatar asked May 28 '12 18:05

Sal Rahman


2 Answers

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

like image 173
VBart Avatar answered Sep 28 '22 10:09

VBart


$time_iso8601 is both machine- & human-friendly.

like image 42
Alex Avatar answered Sep 28 '22 08:09

Alex