Welcome! Log In Create A New Profile

Advanced

Resolver not working as expected

Posted by Sharan J 
Sharan J
Resolver not working as expected
August 27, 2018 03:30PM
Hi,

Sample conf:

http{
resolver x.x.x.x;
server {
server_name _;
location / {
proxy_pass http://somedomain.com;
}
}

I have nameservers configured in my resolv.conf. But, somedomain.com will
be configured in x.x.x.x DNS server only. So, I have specified resolver in
my nginx.conf. However, during startup/reload I get "host not found in
upstream error". Why nginx is not considering resolver conf and searches
only in the nameservers configured in resolv.conf?

Thanks,
Shanthu
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: Resolver not working as expected
August 27, 2018 03:40PM
Hello!

On Mon, Aug 27, 2018 at 06:56:01PM +0530, Sharan J wrote:

> Hi,
>
> Sample conf:
>
> http{
> resolver x.x.x.x;
> server {
> server_name _;
> location / {
> proxy_pass http://somedomain.com;
> }
> }
>
> I have nameservers configured in my resolv.conf. But, somedomain.com will
> be configured in x.x.x.x DNS server only. So, I have specified resolver in
> my nginx.conf. However, during startup/reload I get "host not found in
> upstream error". Why nginx is not considering resolver conf and searches
> only in the nameservers configured in resolv.conf?

Names as written in the configuration are resolved while parsing
the configuration using the system resolver. DNS servers defined
by the "resolver" directive are only used for dynamic / run-time
name resolution - for example, when variables are used in the
"proxy_pass" directive.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Steve Wilson
Re: Resolver not working as expected
August 28, 2018 02:40PM
On 27/08/2018 14:30, Maxim Dounin wrote:
> Hello!
>
> On Mon, Aug 27, 2018 at 06:56:01PM +0530, Sharan J wrote:
>
>> Hi,
>>
>> Sample conf:
>>
>> http{
>> resolver x.x.x.x;
>> server {
>> server_name _;
>> location / {
>> proxy_pass http://somedomain.com;
>> }
>> }
>>
>> I have nameservers configured in my resolv.conf. But, somedomain.com
>> will
>> be configured in x.x.x.x DNS server only. So, I have specified
>> resolver in
>> my nginx.conf. However, during startup/reload I get "host not found in
>> upstream error". Why nginx is not considering resolver conf and
>> searches
>> only in the nameservers configured in resolv.conf?
>
> Names as written in the configuration are resolved while parsing
> the configuration using the system resolver. DNS servers defined
> by the "resolver" directive are only used for dynamic / run-time
> name resolution - for example, when variables are used in the
> "proxy_pass" directive.

I didn't want to hijack this thread but my question seems relevant.

Is there a way to prevent dns resolution on a proxy_pass or upstream
block during config parsing, or at least make it non-fatal?

background/reason: I've a backend server with dynamic IP which doesn't
always resolve. It will resolve when it's expected to be working but may
not be available at config parsing time.
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sharan J
Re: Resolver not working as expected
August 29, 2018 09:00AM
Hi,

Thanks for the response :)

But, if I remove all the DNS servers from my resolv.conf then, the
nameserver configured by the "resolver" directive is been used while
parsing the configuration. Is this an expected behavior?

Thanks,
Shanthu

On Mon, Aug 27, 2018 at 7:00 PM Maxim Dounin <[email protected]> wrote:

> Hello!
>
> On Mon, Aug 27, 2018 at 06:56:01PM +0530, Sharan J wrote:
>
> > Hi,
> >
> > Sample conf:
> >
> > http{
> > resolver x.x.x.x;
> > server {
> > server_name _;
> > location / {
> > proxy_pass http://somedomain.com;
> > }
> > }
> >
> > I have nameservers configured in my resolv.conf. But, somedomain.com
> will
> > be configured in x.x.x.x DNS server only. So, I have specified resolver
> in
> > my nginx.conf. However, during startup/reload I get "host not found in
> > upstream error". Why nginx is not considering resolver conf and searches
> > only in the nameservers configured in resolv.conf?
>
> Names as written in the configuration are resolved while parsing
> the configuration using the system resolver. DNS servers defined
> by the "resolver" directive are only used for dynamic / run-time
> name resolution - for example, when variables are used in the
> "proxy_pass" directive.
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: Resolver not working as expected
August 29, 2018 01:30PM
Hello!

On Wed, Aug 29, 2018 at 12:25:37PM +0530, Sharan J wrote:

> But, if I remove all the DNS servers from my resolv.conf then, the
> nameserver configured by the "resolver" directive is been used while
> parsing the configuration. Is this an expected behavior?

This depends on your system configuration. nginx itself
does not use the DNS servers defined by the "resolver" directive
during configuration parsing, it uses getaddrinfo() and/or
gethostbyname() library functions.

Note that resolv.conf is not the only configuration file to
configure system name resolution - on most systems, there is also
/etc/nsswitch.conf and /etc/hosts to consider.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
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