2

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.