Hi everyone!
I'm dealing with a not-so-small configuration system written in a mixture of Lua and the usual Nginx syntax. There're limits on what I can realistically change/rewrite in this system.
To spare you with unimportant details, here's (a part of) /etc/nginx/upstream-defs.conf:
set_by_lua $foobar_port "FOOBAR_PORT";
server http://localhost:$foobar_port;
That segment is include-d from the top-level nginx.conf like this:
http {
init_by_lua_block {
FOOBAR_PORT = os.getenv('FOOBAR_SERVER_PORT') or "12345"
-- ngx.var.foobar_port = FOOBAR_PORT
}
include /etc/nginx/upstream-defs.conf;
}
Here's where I need help: I have to keep the computation of FOOBAR_PORT (Lua global, yes, sorry) as it is, and somehow use its value in an upstream block.
The way it's written above -- set_by_lua $foobar_port "FOOBAR_PORT" -- doesn't work:
2019/01/22 14:27:06 [emerg] 2767#0: "set_by_lua" directive is not allowed here in /etc/nginx/nginx.conf:138
-- which I can understand, since this use of set_by_lua is neither in a valid context, neither during appropriate phase (access/rewrite VS init).
But it's unclear to me what else I can try. Naïve assignment to ngx.var.foobar_port (commented above) doesn't work, too:
2019/01/22 14:33:13 [emerg] 3390#0: invalid host in upstream "http://localhost:$foobar_port" in /etc/nginx/nginx.conf:141
Any suggestions?.. Thanks in advance.