Removing DNS caching on NGINX proxy pass

2016-09-29

If you’re passing hostnames into your nginx’s proxy_pass and made a change to the hostname’s ip address, you might experience times when nginx is still referencing the old ip address despite your DNS TTL having already been expired.

This is because nginx caches the ip of all hostnames resolved in its configuration.

In order to ensure that any IP change is quickly resolved, you should specify a valid period so that nginx will force a cache refresh on its ip storage.

resolver 127.0.0.1 [::1]:5353 valid=1s

This can be done in any of the following context:

http, server, location

References

I’m currently working on fyra.sh, a CLI-first static site deployment tool where you push your site and it’s served globally through a built-in CDN, without the overhead of heavy platforms.