# DNS Caching Issue For community version

**URL:** <https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609>\
**Category:** NGINX\
**Created:** [May 12, 2016, 11:37am UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609 "2016-05-12T11:37:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [May 12, 2016, 11:37am UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/1 "2016-05-12T11:37:15Z")

</div>

Troubled up in DNS caching of the IP address for a given DNS name.

Adding the solution given below does not solve the problem of DNS  
caching in  
NGINX.

resolver 8.8.8.8;  
set $upstream\_endpoint [https://example.net:8080](https://example.net:8080);  
location / {  
proxy\_pass $upstream\_endpoint;  
}

Is there any solutions?

Posted at Nginx Forum:

> **[DNS Caching Issue For community version](https://forum.nginx.org/read.php?2,266857,266857#msg-266857)**
>
> Troubled up in DNS caching of the IP address for a given DNS name. Adding the solution given below does not solve the problem of DNS caching in NGINX. resolver 8.8.8.8; set $upstream\_endpoint https://example.net:8080; location / { proxy\_pass $u

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 12, 2016, 11:51am UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/2 "2016-05-12T11:51:51Z")

</div>

From Manual:

By default, nginx caches answers using the TTL value of a response. An  
optional|valid|parameter allows overriding it:

```
resolver 127.0.0.1 [::1]:5353 valid=30s;

Before version 1.1.9, tuning of caching time was not possible, and
nginx always cached answers for the duration of 5 minutes.

```

Best regards,  
Vintila Mihai Alexandru

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 12, 2016, 12:02pm UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/3 "2016-05-12T12:02:23Z")

</div>

Even adding the valid parameter the issue was not solved.

Posted at Nginx Forum:

> **[Re: DNS Caching Issue For community version](https://forum.nginx.org/read.php?2,266857,266859#msg-266859)**
>
> Troubled up in DNS caching of the IP address for a given DNS name. Adding the solution given below does not solve the problem of DNS caching in NGINX. resolver 8.8.8.8; set $upstream\_endpoint https://example.net:8080; location / { proxy\_pass $u

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 12, 2016, 12:12pm UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/4 "2016-05-12T12:12:19Z")

</div>

I wanted check whether the resolver solves the DNS in a dynamic manner  
when  
the ip addresses changes.

So I add the given code after several findings and yet the resolving the  
ip  
address is not happening.

server{  
…

resolver 8.8.8.8 valid=30s;  
resolver\_timeout 10s;  
set $upstream “[example.net](http://example.net)”;

location / {  
rewrite ^/(.\*) /$1 break;  
proxy\_pass https://:3000$upstream;

```
    }

```

}

Posted at Nginx Forum:

> **[Re: RE: DNS Caching Issue For community version](https://forum.nginx.org/read.php?2,266857,266862#msg-266862)**
>
> Troubled up in DNS caching of the IP address for a given DNS name. Adding the solution given below does not solve the problem of DNS caching in NGINX. resolver 8.8.8.8; set $upstream\_endpoint https://example.net:8080; location / { proxy\_pass $u

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 12, 2016, 12:50pm UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/5 "2016-05-12T12:50:17Z")

</div>

Have you also checked that the DNS returns the correct value? As the  
valid option means that nginx will ask the DNS server again, but if the  
DNS replies with same old ip… Also you might check using directly the  
hostname as it might be possible that there is a bug when using  
variables.

Best regards,  
Vintila Mihai Alexandru

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 12, 2016, 12:04pm UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/6 "2016-05-12T12:04:43Z")

</div>

> Even adding the valid parameter the issue was not solved.

And what is the issue actually? Just saying “DNS caching issue”  
and “problem” isn’t really helpful.

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 12, 2016, 1:37pm UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/7 "2016-05-12T13:37:01Z")

</div>

Hello!

On Thu, May 12, 2016 at 06:11:36AM -0400, RT.Nat wrote:

> resolver\_timeout 10s;  
> set $upstream “[example.net](http://example.net)”;
> 
> location / {  
> rewrite ^/(.\*) /$1 break;  
> proxy\_pass https://:3000$upstream;
> 
> ```
> }
> 
> ```
> 
> }

Note if you have upstream “[example.net](http://example.net)” defined elsewhere, nginx  
will use it, and dynamic DNS resolution will not be used. Note  
well that upstream may be defined either explicitly, using

```
upstream example.net {
    ...
}

```

or implicitly, using a proxy\_pass to the given name:

```
proxy_pass http://example.net;

```

The latter sometimes confuses people trying to use proxy\_pass with  
variables to trigger dynamic DNS resolution of upstream names.

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 13, 2016, 8:13am UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/8 "2016-05-13T08:13:56Z")

</div>

Not clear regarding, " Also you might check using directly the hostname  
as  
it might be possible that there is a bug when using variables."

I tried adding the variable for resolving the dns but still the ip  
address  
does not changes. Is there any other way? or is there any bug in my  
script.

resolver 8.8.8.8 valid=30s;  
resolver\_timeout 10s;  
set $checkup “[example.net](http://example.net)”;

location / {  
rewrite ^/(.\*) /$1 break;  
proxy\_pass https://:8080$checkup;  
}

even adding the following codes instead of the above proxy pass doesnt  
work.

proxy\_pass https://example.net:8080$request\_uri;  
proxy\_pass [https://example.net:8080](https://example.net:8080);

Posted at Nginx Forum:

> **[Re: DNS Caching Issue For community version](https://forum.nginx.org/read.php?2,266857,266880#msg-266880)**
>
> Troubled up in DNS caching of the IP address for a given DNS name. Adding the solution given below does not solve the problem of DNS caching in NGINX. resolver 8.8.8.8; set $upstream\_endpoint https://example.net:8080; location / { proxy\_pass $u

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 16, 2016, 6:28am UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/9 "2016-05-16T06:28:40Z")

</div>

I cannot install the above module.

/Downloads/nginx-upstream-dynamic-servers-master$ make install  
make: \*\*\* No rule to make target `install’. Stop.

May i know is there any problem in my machine( any required  
prerequistes).

Posted at Nginx Forum:

> **[Re: DNS Caching Issue For community version](https://forum.nginx.org/read.php?2,266857,266913#msg-266913)**
>
> Troubled up in DNS caching of the IP address for a given DNS name. Adding the solution given below does not solve the problem of DNS caching in NGINX. resolver 8.8.8.8; set $upstream\_endpoint https://example.net:8080; location / { proxy\_pass $u

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 15, 2016, 11:02pm UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/10 "2016-05-15T23:02:19Z")

</div>

Maybe You should try this module:

> **[GitHub - GUI/nginx-upstream-dynamic-servers: An nginx module to resolve domain names inside...](https://github.com/GUI/nginx-upstream-dynamic-servers)**
>
> An nginx module to resolve domain names inside upstreams and keep them up to date.

Regards,  
Biazus

On Fri, May 13, 2016 at 3:13 AM, RT.Nat [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> location / {  
> Posted at Nginx Forum:  
> [https://forum.nginx.org/read.php?2,266857,266880#msg-266880](https://forum.nginx.org/read.php?2,266857,266880#msg-266880)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–

_Daniel Biazus, R&DAZION | Deliver. Accelerate. Protect.Office: +55 51  
3012 3005 \<%2B55%2051%203012%203005\> | Mobile: +55 51 8227 9032  
 callto:+555182279032_

Quaisquer informações contidas neste e-mail e anexos podem ser  
confidenciais e privilegiadas, protegidas por sigilo legal. Qualquer  
forma  
de utilização deste documento depende de autorização do emissor, sujeito  
as  
penalidades cabíveis.

Any information in this e-mail and attachments may be confidential and  
privileged, protected by legal confidentiality. The use of this document  
require authorization by the issuer, subject to penalties.

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 17, 2016, 1:05am UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/11 "2016-05-17T01:05:35Z")

</div>

On Fri, May 13, 2016 at 02:13:05AM -0400, RT.Nat wrote:

Hi there,

why do you think that this does not work?

As in: what request do you make that give you an unexpected response?  
And  
can you also show the “dig” command that shows that the nominated dns  
server has changed the resolution address that it provides?

> I tried adding the variable for resolving the dns but still the ip address  
> does not changes. Is there any other way? or is there any bug in my script.

When I use:

# == http { server { listen 8080; resolver 8.8.8.8 valid=20s; set $up “[www.example.net](http://www.example.net)”; location / { proxy\_pass http://$up; } } }

I can do:

date; while :; do curl [http://127.0.0.1:8080/](http://127.0.0.1:8080/); sleep 3; done

and I can also do

tcpdump -nn port 53

and the first command shows the remote web server content every few  
seconds, while the second command show that a new dns request is made  
more than 20 seconds after the previous one:

# === 21:31:00.572450 IP 192.168.224.128.52862 \> 8.8.8.8.53: 12516+ A? [www.example.net](http://www.example.net). (33) 21:31:00.631578 IP 8.8.8.8.53 \> 192.168.224.128.52862: 12516 1/0/0 A 93.184.216.34 (49) 21:31:23.829429 IP 192.168.224.128.52862 \> 8.8.8.8.53: 5096+ A? [www.example.net](http://www.example.net). (33) 21:31:23.873474 IP 8.8.8.8.53 \> 192.168.224.128.52862: 5096 1/0/0 A 93.184.216.34 (49) 21:31:47.135984 IP 192.168.224.128.52862 \> 8.8.8.8.53: 37996+ A? [www.example.net](http://www.example.net). (33) 21:31:47.165754 IP 8.8.8.8.53 \> 192.168.224.128.52862: 37996 1/0/0 A 93.184.216.34 (49)

Now, I don’t control the google name server, and I can’t make  
[www.example.net](http://www.example.net) get an updated address at will; but the above does seem  
to show that the nginx resolver is making a fresh dns request when it  
is supposed to.

Do you see something else in your test?

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![RT.Nat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c89c15/32.png) [@RT.Nat](https://www.ruby-forum.com/u/RT.Nat)\
**Post date:** [May 16, 2016, 12:27pm UTC](https://www.ruby-forum.com/t/dns-caching-issue-for-community-version/244609/12 "2016-05-16T12:27:21Z")

</div>

You have to configure your nginx to use it like any other module.  
For instance,  
cd /Downloads/nginx  
./configure  
–add-module=/Downloads/nginx-upstream-dynamic-servers-master  
make  
make install
