Reputation: 1
In the nginx.conf file, is there a variable that changes only when NGINX server is restarted?
Or how to implement a customized variable that changes only when NGINX server is restarted?
I have tried to use set directive and geo directive as follow:
set $timeStamp '$time_iso8601';
it will change with http request.
Could anyone help for this? Thanks!
Upvotes: 0
Views: 552
Reputation: 3229
As far as I know there is not actually a variable containing this built into nginx.
I'm assuming that there is some outside system actually handling the restarts (or reloads, which is more common) themselves, something like systemd
, supervisord
, etc.
In that case, you can have a script that generates a file that sets the variable, which will be loaded when nginx
reads the configuration.
For example, `/usr/local/nginx/conf/restart_var.conf' might contain:
set $custom_nginx_restart "2017-07-01 3:15:00Z";
You would include this in your server
block.
The would just be generated by a script like:
echo "set \$custom_nginx_restart `date`;" > /usr/local/nginx/conf/restart_var.conf
Alternatively, you can generate something like:
map $http_host $custom_nginx_restart {
default "2017-07-03 3:15:00Z";
}
This can then be included in your http
block.
Note that this would apply both on reloads and restart.
Upvotes: 1