# Disable caching the names in /etc/hosts in reverse proxy?

**URL:** <https://www.ruby-forum.com/t/disable-caching-the-names-in-etc-hosts-in-reverse-proxy/241611>\
**Category:** NGINX\
**Created:** [April 19, 2015, 2:06am UTC](https://www.ruby-forum.com/t/disable-caching-the-names-in-etc-hosts-in-reverse-proxy/241611 "2015-04-19T02:06:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [April 19, 2015, 2:06am UTC](https://www.ruby-forum.com/t/disable-caching-the-names-in-etc-hosts-in-reverse-proxy/241611/1 "2015-04-19T02:06:36Z")

</div>

I’m using Nginx to act as a reverse proxy, where the backend is a name  
defined in /etc/hosts. However, Nginx does not react to the changes made  
in  
/etc/hosts until restarted. Is it possible to disable caching the names  
in  
/etc/hosts in reverse proxy?

Thanks

Posted at Nginx Forum:

> **[Disable caching the names in /etc/hosts in reverse proxy?](https://forum.nginx.org/read.php?2,258188,258188#msg-258188)**
>
> I'm using Nginx to act as a reverse proxy, where the backend is a name defined in /etc/hosts. However, Nginx does not react to the changes made in /etc/hosts until restarted. Is it possible to disable caching the names in /etc/hosts in reverse proxy?...

---

<div class="post-metadata">

**Author:** ![xuhdev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f0a364/32.png) [@xuhdev](https://www.ruby-forum.com/u/xuhdev)\
**Post date:** [April 20, 2015, 7:11pm UTC](https://www.ruby-forum.com/t/disable-caching-the-names-in-etc-hosts-in-reverse-proxy/241611/2 "2015-04-20T19:11:53Z")

</div>

There is no ‘cache’ per se, but rather remembered DNS results, much like  
you do when you deal with domain names to avoid putting to high a burden  
on  
NS resolvers.

nginx resolves names on start or reload.  
The commercial version added a feature to update names periodically  
(resolve  
option of the server directive in the upstream module  
[http://nginx.org/en/docs/http/ngx\_http\_upstream\_module.html#server](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)).  
However, FOSS nginx is stuck with ‘static’ names resolution.

## The commercial version is said to be full-featured, having new features the FOSS version does not have and does not need… questionable when you see such ‘degraded’ features in FOSS, which the commercial version handles the right way. Political/Economical choices I suppose.

_B. R._

---

<div class="post-metadata">

**Author:** ![xuhdev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f0a364/32.png) [@xuhdev](https://www.ruby-forum.com/u/xuhdev)\
**Post date:** [April 20, 2015, 7:53pm UTC](https://www.ruby-forum.com/t/disable-caching-the-names-in-etc-hosts-in-reverse-proxy/241611/3 "2015-04-20T19:53:30Z")

</div>

> On 19 Apr 2015, at 01:05, xuhdev [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> I’m using Nginx to act as a reverse proxy, where the backend is a name  
> defined in /etc/hosts. However, Nginx does not react to the changes made in  
> /etc/hosts until restarted. Is it possible to disable caching the names in  
> /etc/hosts in reverse proxy?

As B.R. mentioned, the DNS lookup (via /etc/hosts or real DNS) is only  
done at startup and reload.

You can change the behaviour to dynamic lookup by specifying a resolver  
in the server block and then using variables in the proxy\_pass. For  
example:

server {  
resolver 8.8.8.8;  
location / {  
proxy\_pass http://reverse\_host$uri$is\_args$args;  
}  
}

Because of the variables Nginx can’t predict at startup what to perform  
a lookup for. As a result it will perform the DNS lookup at request  
time. The lookup response is then cached for the DNS TTL period.

CPU may be a little higher I guess but I haven’t noticed anything even  
on high load clusters.

This behaviour is eluded to in the documentation’s last couple of  
paragraphs for proxy\_pass at:

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

Jason

---

<div class="post-metadata">

**Author:** ![xuhdev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f0a364/32.png) [@xuhdev](https://www.ruby-forum.com/u/xuhdev)\
**Post date:** [April 20, 2015, 8:12pm UTC](https://www.ruby-forum.com/t/disable-caching-the-names-in-etc-hosts-in-reverse-proxy/241611/4 "2015-04-20T20:12:28Z")

</div>

## B.R. Wrote:

> nginx resolves names on start or reload.  
> The commercial version added a feature to update names periodically  
> (resolve  
> option of the server directive in the upstream module  
> [http://nginx.org/en/docs/http/ngx\_http\_upstream\_module.html#server](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)).  
> However, FOSS nginx is stuck with ‘static’ names resolution.

For an alternative method look here,

> **[Redirecting to Google Groups](https://groups.google.com/forum/#!topic/openresty-en/wt_9m7GvROg)**

sources at the end of that thread.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,258188,258236#msg-258236](http://forum.nginx.org/read.php?2,258188,258236#msg-258236)
