An nginx module to resolve domain names inside upstreams and keep them up to date.
By default, servers defined in nginx upstreams are only resolved when nginx starts. This module provides an additional resolve
parameter for server
definitions that can be used to asynchronously resolve upstream domain names. This keeps the upstream definition up to date according to the DNS TTL of each domain names. This can be useful if you want to use upstreams for dynamic types of domain names that may frequently change IP addresses.
This module also allows nginx to start if an upstream contains a defunct domain name that no longer resolves. By default, nginx will fail to start if an upstream server contains an unresolvable domain name. With this module, nginx is still allowed to start with invalid domain names, but an error will be logged and the unresolvable domain names will be marked as down.
./configure --add-module=/path/to/nginx-upstream-dynamic-servers
make && make install
Use the server
definition inside your upstreams and specify the resolve
parameter.
Note: A resolver
must be defined at the http
level of nginx's config for resolve
to work.
http {
resolver 8.8.8.8;
upstream example {
server example.com resolve;
}
}
Syntax: server address [parameters];
Context upstream
Defines a server for an upstream. The module adds the ability to specify a resolve
parameter. When specified:
The following parameters can be used (see nginx's server documentation for details):
weight=number
max_fails=number
fail_timeout=time
backup
down
resolve
Tested with nginx 1.6, 1.7, 1.8, 1.9.
proxy_pass
can perform resolving at run-time.nginx-upstream-dynamic-servers is open sourced under the MIT license.