在 if 语句之前运行 access_by_lua

我想从一个 API 中获取一些文本,如果它等于某些内容,则进行代理传递。 经过一些测试,我发现 access_by_lua 在 if 语句之后执行。

这是我当前的代码:

set $protectione 'disabled';

        access_by_lua_block {
local http = require "resty.http"
local httpc = http.new()

local res, err = httpc:request_uri("http://127.0.0.1/ddos/fw.json", { method = "GET" })
ngx.var.protectione = res.body

        }

   if ( $protectione = 'disabled' ) {

     proxy_pass http://backend;
       set $allowreq 1;

   }

有没有其他解决方案?

点赞
用户2060502
用户2060502

你绝对应该参考下一篇tutorial和这个post

你还没有理解nginx请求处理阶段的概念。

Nginx指令的执行顺序并不是顺序执行。

ifset指令工作在access阶段之前被处理的rewrite阶段上。

2018-06-20 08:36:00