Welcome! Log In Create A New Profile

Advanced

Fetching HTTP value into config at start-up

September 04, 2014 01:07AM
Hi all,

I want to read some remote values via HTTP into nginx config variables, just once at nginx startup / reload time, and pass them as fastcgi_params into PHP scripts. I control the remote system, so I'll know if it needs to re-read and can send a HUP to nginx. I don't need it to happen every request though, because the value won't change for long periods - but it will change sometimes, and I don't want to have push more config out to multiple nginx servers if I can avoid it.

Is there a way to do this that doesn't create problems?

Here's what I've tried so far.

This first one doesn't work, because the "API [is] disabled in the context of set_by_lua*":

set_by_lua $config_variable "
local result = ngx.location.capture('http://url.to.fetch/')
return result
"

(Same with ngx.socket.*)

This next one works; it feels horrible to do this but if it was just once at start-up, it might be OK - but this executes for every incoming request (confirmed by using /bin/date as the 'command' and just hitting refresh):

set_by_lua $config_variable "
local command = "/usr/bin/curl http://url.to.fetch/"
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
return result
"

Same for this one, it executes for every request:

perl_set $config_variable '
sub {
$var = `/bin/date`;
return $var;
}
'

Is there a good way to do this, that only executes once, and doesn't have horrible shell interactions?

Thanks very much for your help,
Igor
Subject Author Posted

Fetching HTTP value into config at start-up

igorclark September 04, 2014 01:07AM

Re: Fetching HTTP value into config at start-up

oscaretu . September 04, 2014 02:38AM

Re: Fetching HTTP value into config at start-up

igorclark September 04, 2014 10:31AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 98
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready