I need nginx to return 200 code on some location only if rewrite_by_lua_block
response contains custom header with pattern (for google compute engine balancer healthcheck).
I'm very newbie in lua, so any help's greatly appreciated.
I suggest to try (untested)
header_filter_by_lua_block {
if ngx.status == 200 then
local from, to, err = ngx.re.find( ngx.header.Foo, "your_regexp_here")
if not from then
ngx.status = 500 -- use the error code you need
end
end
}
Keep in mind - your should place header_filter_by_lua_block
directive into location where your request is really sent to upstream, say where you redirect to by rewrite_by_lua_block
.