【问题标题】:Assign the Lua function to Nginx variable将 Lua 函数分配给 Nginx 变量
【发布时间】:2021-02-04 11:37:01
【问题描述】:

我想将值分配给 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};

有人知道吗?

【问题讨论】:

    标签: nginx lua nginx-reverse-proxy nginx-config openresty


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-28
      • 2018-01-24
      • 1970-01-01
      相关资源
      最近更新 更多