在if之前运行access_by_lua

时间:2018-06-19 04:56:51

标签: nginx lua openresty

我试图从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;

   }   

我的问题有其他选择吗?

1 个答案:

答案 0 :(得分:3)

您绝对应该看看下一个tutorial和这个post

您不了解nginx请求处理阶段的想法。

Nginx指令不会顺序执行。

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