如果 rewrite_by_lua_block 响应 header 包含模式,nginx 返回 200

标签 nginx lua google-compute-engine openresty

仅当 rewrite_by_lua_block 响应包含带有模式的自定义 header (用于 Google 计算引擎平衡器健康检查)时,我才需要 nginx 在某个位置返回 200 代码。

我是 lua 的新手,所以非常感谢任何帮助。

最佳答案

我建议尝试(未经测试)

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
}

请记住 - 您应该将 header_filter_by_lua_block 指令放置到您的请求真正发送到上游的位置,比如您通过 rewrite_by_lua_block 重定向到的位置。

关于如果 rewrite_by_lua_block 响应 header 包含模式,nginx 返回 200,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36578004/

相关文章:

lua - 为什么 lua 解释器中的 -l 选项行为奇怪?

lua - 望远镜查找文件和实时 grep 不起作用

docker - 如何在 Github 操作中为计算引擎虚拟机拉取 Docker 镜像?

google-compute-engine - 如何在 Google Compute Engine 中以编程方式获取实例 IP?

linux - Ssh端口转发谷歌计算引擎

r - Shiny Server - 托管附加应用程序的问题

ruby-on-rails - Nginx + 乘客 : Multiple domains need to point to different root

php - 如何使用 nginx 和 php-fpm 将请求 url 子文件夹路径路由到特定 php 页面

ubuntu - 在 ubuntu 14.04 中更新 nginx

c++ - Lua 用户数据指针的生命周期