点赞
用户7121513
用户7121513

据我所知,return 指令的执行发生在重写阶段,而在这种情况下,访问阶段根本不会执行。您可以尝试将 access_by_lua_block 更改为 rewrite_by_lua_block,看看会发生什么。

更新

尝试解决问题的第一次尝试没有任何结果。确实,如 lua-ngx-module 文档所述,对于 rewrite_by_lua

请注意,此处理程序始终在标准 ngx_http_rewrite_module 之后运行。

您可以尝试在 rewrite_by_lua_block 中执行重定向:

location /abc {
   rewrite_by_lua_block {
      ngx.req.set_header("foo", "bar")
      ngx.redirect("xyz.com", 301)
   }

   header_filter_by_lua_block {
     ngx.header["foo2"] = ngx.var["http_foo"] # 这没有获取上面设置的 "foo" 标头的值
   }
}
2020-06-10 17:36:59