Joel Parker
NGINX lifecycle
November 09, 2017 10:20PM
I want to load a table of key/value pairs from the file system when nginx
starts and not every time a request comes in. I am going to use the
key/value pairs to compare against incoming post args in my location block.

My question is how many times is init_by_lua_block called ? or is there
somewhere else I should be loading the file ?

server {
init_by_lua_block {
some_global_var = stuff from file io read;
}

location \ {
...
}
}
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: NGINX lifecycle
November 10, 2017 12:50PM
Hello!

On Thu, Nov 09, 2017 at 03:17:36PM -0600, Joel Parker wrote:

> I want to load a table of key/value pairs from the file system when nginx
> starts and not every time a request comes in. I am going to use the
> key/value pairs to compare against incoming post args in my location block.
>
> My question is how many times is init_by_lua_block called ? or is there
> somewhere else I should be loading the file ?
>
> server {
> init_by_lua_block {
> some_global_var = stuff from file io read;
> }
>
> location \ {
> ...
> }
> }

For key-value pairs there is the map module in nginx, there is no
need to use 3rd party modules. See
http://nginx.org/en/docs/http/ngx_http_map_module.html for
details.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Nelson, Erik - 2 via nginx
RE: NGINX lifecycle
November 10, 2017 03:10PM
> On Thu, Nov 09, 2017 at 03:17:36PM -0600, Joel Parker wrote:
>
> > I want to load a table of key/value pairs from the file system when nginx
> > starts and not every time a request comes in. I am going to use the
> > key/value pairs to compare against incoming post args in my location block.
> >
> > My question is how many times is init_by_lua_block called ? or is there
> > somewhere else I should be loading the file ?

Looks like once to me.

https://github.com/openresty/lua-nginx-module#init_worker_by_lua_block says

Runs the specified Lua code upon every Nginx worker process's startup when the master process is enabled. When the master process is disabled, this hook will just run after init_by_lua*.

Also, there's an openresty-en mailing list, that might be a better place for openresty-specific questions.


----------------------------------------------------------------------
This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at http://www.bankofamerica.com/emaildisclaimer. If you are not the intended recipient, please delete this message.
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login