Global Lua Modules

Global Lua modules provide a powerful mechanism for implementing complex logical functionalities. Unlike YAML configuration files, global Lua modules use the .lua file extension and must be placed in a subdirectory called global_lua_modules within the configuration directory.

Example

Create a Lua module named hello.lua:

local _M = {}

function _M.go()
    ngx.say("hello")
end

return _M

Invoke the hello Lua module in the page rules:

- enable_rule: true
  actions:
    "user-code":
      el: |-
        {
        true =>
            foreign-call(module: "hello", func: "go"),
            done;
        }
  comment: ''

In the above example, a simple Lua module hello.lua contains a function named go that outputs “hello”. Then, in the page rule configuration, this module and function are invoked through the expression.