Nginx – Flushing Nginx DNS cache while using upstream load balancing

nginx

I've recently encountered an issue where due to the DNS cache within Nginx a service was negatively impacted because we use upstream settings within the associated Nginx configuration. I've reviewed the following issue already as well as searching for a solution, none of them use upstream: https://stackoverflow.com/questions/26956979/error-with-ip-and-nginx-as-reverse-proxy . Due to the fact we use an AWS ELB we identify two of the same server values that sit inside the upstream. The relevant section looks like this:

upstream my_server {
  server blah.domain.com:443;
  server blah.domain.com:443;
}

server {

  listen 1024;
  access_log /var/log/nginx/my-access-log.log;
  error_log /var/log/nginx/my-error-log.log;

  keepalive_timeout 5;
  client_max_body_size 40M;

  location /blah {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host blah.domain.com;
    proxy_redirect off;
    proxy_pass https://my_server;
}

So I know that I could use a resolver and create an http section which the server section sits inside of, however I can't set a variable that will then use the Nginx load balancer functionality. I can't set a variable inside of upstream as it is not supported (which would force the DNS cache to refresh as noted here: http://forum.nginx.org/read.php?2,215830,215832#msg-215832).

So my question is how do I work around this? How do I maintain the functionality that upstream provides for load balancing while also ensuring the DNS cache is flushed without restarting the service in the community version of Nginx?

Best Answer

The functionality described is provided in NGINX Plus, the complete application delivery platform that provides additional features.

You can read about the "On-the-Fly Reconfiguration" functionality provided by NGINX Plus and see the documentation under the "Dynamically Configurable Group" section for more information about this specific feature.

(Disclaimer: I am affiliated with NGINX, Inc - the company that develops both versions of NGINX).