将 Lua 函数分配给 Nginx 变量

Assign the Lua function to Nginx variable

我想给nginx变量赋值。
这是我的示例代码。

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};

有人知道吗?

使用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;
}