Resolver directive doesn't fallback to the system DNS resolver

Hello,
I am looking at how to use nginx’s resolver directive
(Module ngx_http_core_module) to
address this one issue i am facing. I have a host for which there is
already an entry in the system DNS resolver (verified using
nslookup/dig) but when i specify the same host in the proxy_pass
directive inside a location block, i get the following error thrown in
nginx.log
015/01/05 14:24:13 [error] 22560#0: *5 no resolver defined to resolve

Seems like nginx is not falling back to the system DNS resolver in case
the ‘resolver’ directive is not used. Isn’t this incorrect behaviour ?

Thanks
-Kunal

Ping…

Thanks
-Kunal

From: “Kunal P.” [email protected]
To: [email protected]
Sent: Monday, January 5, 2015 3:04:52 PM
Subject: resolver directive doesn’t fallback to the system DNS resolver

Hello,
I am looking at how to use nginx’s resolver directive
(Module ngx_http_core_module) to
address this one issue i am facing. I have a host for which there is
already an entry in the system DNS resolver (verified using
nslookup/dig) but when i specify the same host in the proxy_pass
directive inside a location block, i get the following error thrown in
nginx.log
015/01/05 14:24:13 [error] 22560#0: *5 no resolver defined to resolve

Seems like nginx is not falling back to the system DNS resolver in case
the ‘resolver’ directive is not used. Isn’t this incorrect behaviour ?

Thanks
-Kunal


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

On Mon, Jan 05, 2015 at 05:04:52PM -0600, Kunal P. wrote:

Hi there,

015/01/05 14:24:13 [error] 22560#0: *5 no resolver defined to resolve …

Seems like nginx is not falling back to the system DNS resolver in case the
‘resolver’ directive is not used. Isn’t this incorrect behaviour ?

==
events {}
http {
server {
listen 8080;
location /one {
proxy_pass http://www.example.com;
}
}
}

Works for me.

What config file shows the problem that you report?

(If the above fails for you, then it may be worth examining external
parts.)

f

Francis D. [email protected]

On Wed, Jan 07, 2015 at 05:37:22PM -0600, Kunal P. wrote:

Hi there,

http {
server {
listen 443;
location ^~ /zss
{
proxy_pass https://www.example.com$request_uri;
}
}
}

Ok, I see the “no resolver defined to resolve www.example.com” message
when I make a request that matches that location.

Although i don’t want to use this resolver directive here and instead just want
nginx to use the system DNS resolver (from /etc/resolv.conf). Is there a way to
achieve this ?
Unless something has changed recently that I haven’t seen, my
understanding is:

if the hostname is known at start time, nginx will use the system
resolver
to resolve it, and will use the result forever

otherwise, you must use a “resolver” directive to tell nginx which name
servers to use for runtime resolution.

http://nginx.org/r/resolver

There is no default for “resolver”; if you want one to be used, you must
configure it explicitly. So I think the answer to your question is “no”.

(You could probably come up with a way to read /etc/resolv.conf when it
changes, and update the nginx config and reload it; but that’s a
“dynamic
reconfiguration” problem, not an “nginx dynamic reconfiguration”
problem.)

f

Francis D. [email protected]

This is what i have.

http {
server {
listen 443;
location ^~ /zss
{
proxy_pass https://www.example.com$request_uri;
}
}
}

Now as per
nginx AWS ELB name resolution with resolvers — Greg Taylor,
If you are running nginx as a proxy in front of An Amazon Web Services
Elastic Load Balancer (ELB) which is the case for me, it is not safe to
merely define an upstream using the hostname of ELB and call it a day.
Although i don’t want to use this resolver directive here and instead
just want nginx to use the system DNS resolver (from /etc/resolv.conf).
Is there a way to achieve this ?

Thanks
-Kunal

From: “Francis D.” [email protected]
To: [email protected]
Sent: Wednesday, January 7, 2015 3:14:17 PM
Subject: Re: resolver directive doesn’t fallback to the system DNS
resolver

On Mon, Jan 05, 2015 at 05:04:52PM -0600, Kunal P. wrote:

Hi there,

015/01/05 14:24:13 [error] 22560#0: *5 no resolver defined to resolve

Seems like nginx is not falling back to the system DNS resolver in case
the ‘resolver’ directive is not used. Isn’t this incorrect behaviour ?

==
events {}
http {
server {
listen 8080;
location /one {
proxy_pass http://www.example.com;
}
}
}

Works for me.

What config file shows the problem that you report?

(If the above fails for you, then it may be worth examining external
parts.)

f

Francis D. [email protected]


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Hello!

On Wed, Jan 7, 2015 at 4:15 PM, Francis D. wrote:

(You could probably come up with a way to read /etc/resolv.conf when it
changes, and update the nginx config and reload it; but that’s a “dynamic
reconfiguration” problem, not an “nginx dynamic reconfiguration” problem.)

Yeah, I think it’s better for the nginx resolver to automatically use
whatever is defined in /etc/resolv.conf when the user does not
configure the “resolver” directive in her nginx.conf.

I’m already tired of seeing all those user questions regarding the
error message “no resolver defined to resolve …” over the years.
Alas.

Regards,
-agentzh

Is there already a patch for this ?
I am not completely sure of how to make the nginx resolver (in
ngx_resolver.c) fallback to libresolv automatically and if this not
trivial enough, i just might read the resolvers from /etc/resolv.conf
and provide it to the ‘resolver’ directive. Any suggestions ?

Thanks
-Kunal

----- Original Message -----
From: “Yichun Z. (agentzh)” [email protected]
To: [email protected]
Sent: Wednesday, January 7, 2015 4:30:06 PM
Subject: Re: resolver directive doesn’t fallback to the system DNS
resolver

Hello!

On Wed, Jan 7, 2015 at 4:15 PM, Francis D. wrote:

(You could probably come up with a way to read /etc/resolv.conf when it
changes, and update the nginx config and reload it; but that’s a “dynamic
reconfiguration” problem, not an “nginx dynamic reconfiguration” problem.)

Yeah, I think it’s better for the nginx resolver to automatically use
whatever is defined in /etc/resolv.conf when the user does not
configure the “resolver” directive in her nginx.conf.

I’m already tired of seeing all those user questions regarding the
error message “no resolver defined to resolve …” over the years.
Alas.

Regards,
-agentzh


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Thanks Yichun Z…

----- Original Message -----
From: “Yichun Z. (agentzh)” [email protected]
To: [email protected]
Sent: Monday, January 12, 2015 2:19:08 PM
Subject: Re: resolver directive doesn’t fallback to the system DNS
resolver

Hello!

On Mon, Jan 12, 2015 at 1:48 PM, Kunal P. wrote:

Is there already a patch for this ?

AFAIK, the Tengine fork has a patch for this.

I am not completely sure of how to make the nginx resolver (in ngx_resolver.c)
fallback to libresolv automatically and if this not trivial enough, i just might
read the resolvers from /etc/resolv.conf and provide it to the ‘resolver’
directive. Any suggestions ?

I was not talking about falling back to libresolv because it is very
likely to block the nginx event loop or introduce extra OS threads for
no good. I was talking about extracing nameserver addresses
automatically from /etc/resolv.conf (or similar places in other exotic
operating systems) and feed them into nginx’s current nonblocking
resolver.

And yes, for now, the latter workaround should be the simplest for you
:slight_smile:

Regards,
-agentzh


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

kunalvjti Wrote:

Is there already a patch for this ?
I am not completely sure of how to make the nginx resolver (in
ngx_resolver.c) fallback to libresolv automatically and if this not

Have a look at a Lua solution, not everything works yet,
patches/ideas/feedback welcome :slight_smile:
http://nginx-win.ecsds.eu/devtest/EBLB_upstream_dev1.zip

Posted at Nginx Forum:

Sorry am new to Lua but can you plz explain how this upstream status &
control will help with this issue. How can i query for the upstream ip
after every certain time interval and reconfigure nginx if there’s a
change detected ?
The reason for not using nginx’s resolver here is that i have to parse
the resolv.conf to get the nameservers which is not a clean solution as
there are still some linux distros that don’t use /etc/resolv.conf. This
should be OS & implementation independent. How to make this work
everywhere ?

Thanks
-Kunal

From: “itpp2012” [email protected]
To: [email protected]
Sent: Tuesday, January 13, 2015 1:58:32 AM
Subject: Re: resolver directive doesn’t fallback to the system DNS
resolver

kunalvjti Wrote:

Is there already a patch for this ?
I am not completely sure of how to make the nginx resolver (in
ngx_resolver.c) fallback to libresolv automatically and if this not

Have a look at a Lua solution, not everything works yet,
patches/ideas/feedback welcome :slight_smile:
http://nginx-win.ecsds.eu/devtest/EBLB_upstream_dev1.zip

Posted at Nginx Forum:


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Hello!

On Mon, Jan 12, 2015 at 1:48 PM, Kunal P. wrote:

Is there already a patch for this ?

AFAIK, the Tengine fork has a patch for this.

I am not completely sure of how to make the nginx resolver (in ngx_resolver.c)
fallback to libresolv automatically and if this not trivial enough, i just might
read the resolvers from /etc/resolv.conf and provide it to the ‘resolver’
directive. Any suggestions ?

I was not talking about falling back to libresolv because it is very
likely to block the nginx event loop or introduce extra OS threads for
no good. I was talking about extracing nameserver addresses
automatically from /etc/resolv.conf (or similar places in other exotic
operating systems) and feed them into nginx’s current nonblocking
resolver.

And yes, for now, the latter workaround should be the simplest for you
:slight_smile:

Regards,
-agentzh

kunalvjti Wrote:

Sorry am new to Lua but can you plz explain how this upstream status &
control will help with this issue. How can i query for the upstream ip

Use the ngxlua --add option
(https://github.com/chaoslawful/lua-nginx-module) or openresty, then add
GitHub - openresty/lua-upstream-nginx-module: Nginx C module to expose Lua API to ngx_lua for Nginx upstreams
replace the .c file from my archive and compile.

In the same archive you will find an example full working nginx config
file
and 2 lua files giving you upstream access via a GUI or via Curl.

after every certain time interval and reconfigure nginx if there’s a
change detected ?

This can be done in Lua or you can let an external monitoring tool
trigger a
script firing a curl command.

This should be OS & implementation independent. How to make this work
everywhere ?

What I’ve made so far works for any OS.

Posted at Nginx Forum: