How to run a valid OpenResty "nginx.conf" with `resty` CLI?

238 Views Asked by At

The following excerpt is from https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/process.md. How can I run the code with resty CLI without launching OpenResty (Nginx)? It's tedious to restart/reload a full Nginx daemon each time I update the snippets.

# http config
init_by_lua_block {
    local process = require "ngx.process"

    -- enables privileged agent process
    local ok, err = process.enable_privileged_agent()
    if not ok then
        ngx.log(ngx.ERR, "enables privileged agent failed error:", err)
    end

    -- output process type
    ngx.log(ngx.INFO, "process type: ", process.type())
}

init_worker_by_lua_block {
    local process = require "ngx.process"
    ngx.log(ngx.INFO, "process type: ", process.type())
}

server {
    # ...
    location = /t {
        content_by_lua_block {
            local process = require "ngx.process"
            ngx.say("process type: ", process.type())
            ngx.say("master process pid: ", process.get_master_pid() or "-")
        }
    }
}
1

There are 1 best solutions below

2
On

I am not aware of the resty-tool, but:

As an alternative to using the _block directives, you could switch to using files. For me, files do always make more sense, because of cleaner structure, and better highlighting.

You can then disable the lua-file caching (Docs) to ensure the lua-files are re-read on every request.