3

I would like to assign the value to the nginx variable.
This is my sample code.

location / {
    set $TOKEN;
    content_by_lua_block {
        result = io.popen("echo 'https://google.com'") # or any command that will return value to result
        ngx.var.TOKEN = result:read()
    }
    proxy_pass ${TOKEN};

Do anyone have idea about it?

zzob
  • 993
  • 3
  • 9
  • 19

1 Answers1

4

Use set_by_lua_block:

location / {
    set $proxy '';              
    set_by_lua_block $proxy {
        local result = io.popen("echo 'https://www.google.com'")
        return result:read()
    }
    proxy_pass $proxy;
}
un.def
  • 1,200
  • 6
  • 10