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