2

I'm trying to get some text from an api then proxy pass if it equals to something. After some testing, I discovered that the access_by_lua is getting executed after the if statement.

Here's my current code:

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;

   }   

Is there an alternative to my problem ?

Jobine23
  • 129
  • 9

1 Answers1

4

You definitely should take a look at next tutorial and this post

You don't get the idea of nginx request processing phases.

Nginx directives are not executed sequentaly.

if and set directives work on rewrite phase which is processed before access phase.

Alexander Altshuler
  • 2,930
  • 1
  • 17
  • 27