Configuring Dynamic DNS Resolution in NGINX Open Source and NGINX Plus¶
This article explains the difference between static and dynamic DNS resolution in NGINX and how to configure dynamic DNS resolution.
NGINX resolves domain names when connecting to upstream servers, and the process differs depending on whether DNS resolution is static or dynamic.
Static DNS resolution¶
With static DNS resolution, NGINX looks up the IP address only once when it starts. If the DNS record changes, NGINX continues using the old IP until it is reloaded or restarted.
Example configuration using static DNS resolution:
Dynamic DNS resolution¶
With dynamic DNS resolution, NGINX periodically re-resolves hostnames at runtime, so it detects IP changes automatically without needing a restart or reload.
Open-source NGINX availability
Dynamic DNS resolution is available in open-source NGINX since version 1.27.3.
To configure dynamic DNS resolution:
-
Add the
resolvedirective parameter to your upstreamserverdirective, and use a resolvable hostname as your address: -
Define the DNS server with the
resolverdirective: -
Define the name and size of the shared memory zone using the
zonedirective. This keeps configuration and runtime state between worker processes: -
(Optional) Set the resolver timeout using the
resolver_timeoutdirective:
Below is an example configuration for dynamic DNS resolution:
http {
resolver 192.0.2.1 valid=30s;
resolver_timeout 10s;
upstream backend {
zone backend 64k;
server backend1.example.com resolve;
server backend2.example.com resolve;
}
server {
location / {
proxy_pass http://backend;
}
}
}
Impact of dynamic DNS resolution on traffic processing
NGINX re‑resolves domain names when the DNS TTL expires. To instruct NGINX to ignore the TTL and re‑resolve names more often, add the valid parameter to the resolver directive, e.g.: