I’m using Nginx to act as a reverse proxy, where the backend is a name
defined in /etc/hosts. However, Nginx does not react to the changes made
in
/etc/hosts until restarted. Is it possible to disable caching the names
in
/etc/hosts in reverse proxy?
There is no ‘cache’ per se, but rather remembered DNS results, much like
you do when you deal with domain names to avoid putting to high a burden
on
NS resolvers.
nginx resolves names on start or reload.
The commercial version added a feature to update names periodically
(resolve
option of the server directive in the upstream module http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server).
However, FOSS nginx is stuck with ‘static’ names resolution.
The commercial version is said to be full-featured, having new features
the
FOSS version does not have and does not need… questionable when you
see
such ‘degraded’ features in FOSS, which the commercial version handles
the
right way. Political/Economical choices I suppose.
I’m using Nginx to act as a reverse proxy, where the backend is a name
defined in /etc/hosts. However, Nginx does not react to the changes made in
/etc/hosts until restarted. Is it possible to disable caching the names in
/etc/hosts in reverse proxy?
As B.R. mentioned, the DNS lookup (via /etc/hosts or real DNS) is only
done at startup and reload.
You can change the behaviour to dynamic lookup by specifying a resolver
in the server block and then using variables in the proxy_pass. For
example:
Because of the variables Nginx can’t predict at startup what to perform
a lookup for. As a result it will perform the DNS lookup at request
time. The lookup response is then cached for the DNS TTL period.
CPU may be a little higher I guess but I haven’t noticed anything even
on high load clusters.
nginx resolves names on start or reload.
The commercial version added a feature to update names periodically
(resolve
option of the server directive in the upstream module http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server).
However, FOSS nginx is stuck with ‘static’ names resolution.