Nginx DNS and Upstream Discovery: Resolver, TTL and Dynamic Peers
Names can outlive addresses
A service called catalog.test may move from one IP address to another while keeping the same name. DNS maps a name to records, but a cached answer can still point to the earlier address. The TTL (time to live) says how long an answer may be cached; it is not an application health result.
upstream catalog_static { server catalog.test:8080;}Without runtime resolution, a conventional hostname in a static upstream is resolved when configuration is loaded. It is not automatically refreshed simply because its DNS record has changed. A controlled reload can refresh static resolution, but requires working name resolution at that time. A hostname resolving to multiple addresses can represent multiple peers.
Runtime address discovery
resolver 127.0.0.1:15353 valid=15s ipv6=off;resolver_timeout 2s;upstream catalog_dynamic { zone catalog_dynamic 64k; server catalog.test:8080 resolve;}This requires a trusted local DNS service on the illustrated port with a catalog.test record; no such service is shipped in this lab. The shared zone holds changing peer membership. The resolve parameter tracks address changes using the configured resolver. It became available in Open Source in 1.27.3; earlier versions offered it commercially. The upstream-context resolver and resolver_timeout directives likewise have edition/version restrictions. The installed 1.26.3 binary is not a suitable OSS test target for this dynamic group. Do not put unsupported directives into an older config.
By default, the runtime resolver uses answer TTLs. valid=15s overrides that cache validity. resolver_timeout bounds name resolution, not backend connection establishment or total client latency. A and AAAA records represent IPv4 and IPv6 addresses. ipv6=off is only appropriate for an explicitly IPv4-only lab; do not disable IPv6 as a generic production fix.
Reason about stale answers
t=0 catalog.test A 192.0.2.10 TTL 30t=5 authoritative address changes to 192.0.2.20t=10 cached 192.0.2.10 may still be usedt=30 cache can expire; a fresh lookup may return 192.0.2.20These documentation addresses are not lab destinations. With a 15-second validity override, expiry can occur sooner; actual observation depends on resolver behavior and when lookup happens. DNS failure, delayed propagation and long-lived connections can complicate migration. A fresh address does not prove a ready application. Keep a safe overlap between old and new endpoints and verify responses.
Discover service ports with SRV records
upstream discovered_catalog { zone discovered_catalog 64k; server catalog.test service=http resolve;}SRV records describe service targets and ports, plus priority and weight. This configuration looks up the HTTP service record for the name and must not specify a port on the server parameter. Nginx maps the highest-priority SRV records to primary peers and lower priorities to backup peers under the documented default behavior. This is separate from application readiness. Verify DNS and peer behavior on the actual build before using SRV in production.
Diagnose discovery without exposing infrastructure
Check configured resolver address, trusted network, record family, returned TTL, upstream membership and observed response markers. Use synthetic records and an approved local resolver. A DNS answer is not permission to proxy arbitrary client-selected URLs. Keep upstream names operator-controlled. The offline exercise uses a timeline only; runtime DNS and SRV behavior are not tested in this batch.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Nginx DNS and Upstream Discovery: Resolver, TTL and Dynamic Peers
Distinguish startup name resolution from runtime discovery and choose a version-compatible configuration.
What does a TTL describe?
Which OSS version introduced upstream resolve support?
What else is required with resolve in a dynamic upstream?
What does resolver_timeout bound?
When using service=http resolve, what should the server address omit?