Chapter 6
[ 125 ]
server {
resolver 192.168.100.2 valid=300s;
}
Table: Name resolution directives
Directive Explanation
resolver Configures one or more name servers to be
used to resolve upstream server names into
IP addresses. An optional valid parameter
overrides the TTL of the domain name
record.
In order to get NGINX to resolve an IP address anew, place the logical name into
a variable. When NGINX resolves that variable, it implicitly makes a DNS look-up
to find the IP address. For this to work, a resolver directive must be configured:
server {
resolver 192.168.100.2;
location / {
set $backend upstream.example.com;
proxy_pass http://$backend;
}
}
Of course, by relying on DNS to find an upstream, you are dependent on the resolver
always being available. When the resolver is not reachable, a gateway error occurs.
In order to make the client wait time as short as possible, the resolver_timeout
parameter should be set low. The gateway error can then be handled by an error_
page designed for that purpose.
server {
resolver 192.168.100.2;
resolver_timeout 3s;
error_page 504 /gateway-timeout.html;