可以使用ngx.var变量来获取在content_by_lua_block中设置的nginx变量的值。例如:

location /test {
  content_by_lua_block {
    ngx.var.my_var = "hello world"
  }

  # 在同一个location中使用
  return 200, ngx.var.my_var
}

在上面的示例中,我们在content_by_lua_block中设置了一个变量my_var的值为"hello world"。然后在同一个location中,我们可以使用ngx.var.my_var来获取该变量的值,并将其返回给客户端。

content_by_lua_block中设置了nginx某个变量的值怎么在content_by_lua_block外部使用nginx获取到变量的值呢在同一个location中的

原文地址: https://www.cveoy.top/t/topic/cRmU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录