resolver directive takes only hardcoded IP?

884 views
Skip to first unread message

Karen Cushing

unread,
Apr 8, 2016, 10:08:03 AM4/8/16
to openresty-en
I'd like my conf file to handle a configurable resolver. I attempted to do this with an environment variable passed in at runtime via -e, then using set_by_lua to retrieve the value and eventually use in the resolver directive. I am using other environment variables for other purposes so I am confident I have the right syntax for defining and retrieving the variables.

I can hardcode an IP with the resolver directive and it works ok.

But when I try something like
resolver $resolver_value;
I get an error saying "host not found in resolver $resolver_value"

Am I trying to do something that's an unsupported use case?

Yichun Zhang (agentzh)

unread,
Apr 15, 2016, 4:12:08 PM4/15/16
to openresty-en
Hello!
The "resolver" directive is provided by the official nginx:

http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver

And it does not support nginx variables.

If you want more flexibility, then you should consider using the
lua-resty-dns library instead which is designed specifically for nginx
and nonblocking:

https://github.com/openresty/lua-resty-dns

Regards,
-agentzh

Lord Nynex

unread,
Apr 19, 2016, 1:34:57 PM4/19/16
to openre...@googlegroups.com
Hello,

I'd like to add to agentzh's response.

I find myself in a similar boat where my resolver can be dynamic or environmentally specific. A very common example use case for this is AWS VPC networks that use route53 private hosted zones to provide split horizon DNS. 

Unfortunately there is no simple way to deal with this situation. As agentzh mentioned, using lua-resty-dns is the most optimal and flexible solution in these cases. 

An alternative is to use config file templating. Something like consul-template is well suited for this task. It would be trivial to implement this functionality in a small python, perl or bash script as well. I definitely do not like templating my config files, but this is one of a handful of edge cases where it may be your most direct solution. 

Another frustrating edge case is the location of GEOIP .dat files. I have some legacy environments that store this data in differing locations. The geoip module does not support variables and even if it did, you would not be able to find the correct path in lua code and set the variable before nginx attempts to parse and load the database. 

Anyways just my $0.02. 

-Brandon

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages