DNS cache in nginx

Hello ,

I have an A record which resolve to 2 CNAME’s , the DNS failover will
make the switch if something go wrong .

The problem is that after a change the nginx stick to the OLD IP
unless I reload it …
any way the Caching can be disabled ?
I tried the following with no success :
add valid for the resolver ,
resolver valid=5s;
and or
resolver_timeout 1s;

Any recommendation to solve it ?

– shay


On Sat, Jul 04, 2015 at 09:42:06AM +0300, Shay Peretz wrote:

resolver valid=5s;
and or
resolver_timeout 1s;

Any recommendation to solve it ?

As long as you write host names in nginx configuration, nginx will
resolve these names while parsing the configuration. It won’t
notice any changes unless the configuration is reloaded.

If you want nginx to periodically re-resolve names, there are two
options available:

  1. Use proxy_pass with variables:

    set $upstream “backend.example.com”;
    proxy_pass http://$upstream;

When variables are used in the “proxy_pass” directive, nginx
will resolve names at runtime. See http://nginx.org/r/proxy_pass
for details.

  1. Use the “resolve” flag in an upstream{} block. Only available
    in nginx plus, see
    for details.

Alternatively, you may consider using nginx mechanisms to do
failover instead. See these links for some details:


Maxim D.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs