Nginx custom module multi process help


I’m new to nginx development and I have to work on a custom nginx

The module is designed to provide a list of variables for the user to
use in
the nginx.conf file. Whenever those variables are used, the module makes
udp request to a helper server to get the correct value of that

Example (log_format directive)

log_format test_log ‘$closest_chinese_restaurant

As it’s set up now (I wrote this a few months ago using Emiller’s guide
nginx module development and this module on github,

Whenever one of those variables ($closest_ice_cream_shop) is accessed,
module makes a call to the database and gets the value based on the
connections ip address and returns it for use in the conf file. The
is that many of the variables in the module can be retrieved with a
query to the helper server. As it stands now, that log directive will
two calls to the helper server : one for $closest_chinese_restaurant and
for $closest_ice_cream_shop.

How can I make it so that I only have to do one query for multiple
variables? Can I get/set environment variables for use in the conf file
inside the module code? I considered making structs to hold the data so
any request will check if the ip address is the same as previously
queried -
and if it is, then retrieve the cached value from the structs. I’m just
worried that if the server gets busy enough, there will be multiple
instances of my module in different worker processes, which will lead to
multiple caching arrays/structs and trying to retrieve what might not
for that particular instance.

Right now, I have 3 getters for all of my variables : one for ints, one
floats, one for strings. They make a query to the helper server each
time a
variable is accessed in the conf file. Each of those setters is similar
ngx_http_geoip2_variable() in the geoip2 module linked above (they get
data via a query and set the ngx_http_variable_value_t *v).

Please help. Thanks.

Posted at Nginx Forum:

Why not use Lua, collect the data from your variables, run the query
optionally store them in a Lua cache) and process it all real-time,
none-blocking and without any (extra) module.


Posted at Nginx Forum:

If the external server that I’m getting the data from doesn’t have a
relational database (and instead responds to udp requests), will I still
able to cache multiple fields from one udp request using Lua so that I
access them in the conf file later? Can you clarify what you mean by Lua
cache? Thank you for your help!

Posted at Nginx Forum:

Theoretically yes, it all depends how and by what means this data is
collected and if you need to wait for some parts, have a look at the
Urls I send before or join the openresty forum on googlegroups with some
example code/description what your after.

nb. a Lua cache is an in-memory cache of requests/answers that would be
same if run again, if so you serve them from cache (which is fast)
of querying the database (which is ‘slow’) again.

Posted at Nginx Forum:

I will definitely join the google group and check out Lua. Thanks for

Posted at Nginx Forum: