Reputation: 1427
I have different versions of a backend service, and would like nginx to be like a "traffic cop", sending users ONLY to the currently online live backend service. Is there a simple way to do this without changing the nginx config each time I want to redirect users to a different backend service?
In this example, I want to shut down the live backend service and direct users to the test backend service. Then, vice-versa. I'm calling it a logical "traffic cop" which knows which backend service to direct users to.
I don't think adding all backend services to the proxy_pass
using upstream
load balancing will work. I think load balancing would not give me what I'm looking for.
I also do not want user root
to update the /etc/hosts
file on the machine, because of security and collision concerns with multiple programs editing /etc/hosts
simultaneously.
I'm thinking of doing proxy_pass http://live-backend.localhost
in nginx and using a local DNS server to manage the internal IP for live-backend-localhost
which I can change (re-point to another backend IP) at any time. However, would nginx actually query the DNS server on every request, or does it resolve once then cache the IP forever?
Am I over-thinking this? Is there an easy way to do this within nginx?
Upvotes: 1
Views: 255
Reputation: 1107
You can use the backup parameter to the server directive so that the test server will only be used when the live one is down.
NGINX queries DNS on startup and caches it, so you'd still have to reload it to update.
Upvotes: 1