I have docker compose with nginx and nodejs app. When re-building nodejs app its IP can get changed so i specified resolver:
resolver 127.0.0.11 valid=10s;
server {
location /api/ {
set $backend_servers nodejs_app;
proxy_pass http://$backend_servers:8080;
}
}
It's the example from docs: https://www.f5.com/company/blog/nginx/dns-service-discovery-nginx-plus
I'm worried about valid=10s parameter. What happens if the nodejs_app IP has been changed in between, and not able to connect old IP, so service will be down for 10s or it will ask resolver again in case of error?
Also, what if i don't specify valid parameter? Does nginx use TTL (Time‑to‑Live) instead of "valid" parameter or will it always try to resolve?
The documentation gives this syntax:
Syntax: resolver address ... [valid=time] [ipv4=on|off] [ipv6=on|off] [status_zone=zone];
Default: —
Context: stream, server
The documentation goes on with saying this:
By default, nginx caches answers using the TTL value of a response. The optional valid parameter allows overriding it:
resolver 127.0.0.1 [::1]:5353 valid=30s;
So it's a cache length time and you will either remove this valid part if you trust the TTL value, or you need to figure out the best valid time for you based on your project specification, use-cases and technical scenarios. It's a value you need to research if you customize to be sure and we cannot do it on your behalf.
However, the good thing is that it's not written in stone, so if you happen to choose the wrong value, you can customize it. So, instead of worry you can test and monitor and, if necessary adjust.