We want to setup failover mechanism for one of java applications, application have 3 instances on one server and each instance must be accessed via different url, those url's are already registered and accessible via dns. On secondary server we do replication (important part is that instances can be started and run only on one physical machine) therefore we established secondary server in case primary goes down, we wanted to register multiple IP's for one domain but it caused troubles since app's are designed to have only one IP registered to instance url. Another problem with multiple ip setup is round robin nature of dns. Is it possible to have registered two IP's for one domain and to proxy it via nginx or HAproxy to point to only master server? Or some other idea ? My idea is if primary goes down, turn on application on secondary server and change config on nginx side if possible to avoid dns registration and propagation time?
Asked
Active
Viewed 310 times
1 Answers
1
What I would do, is accept incoming traffic on the domain's actual name, and manually do the routing/failover yourself.
i.e.
example.com > nginx server > server1. (if failed) > server2.
http { upstream java-app { server $primary-server; server $secondary-server backup; } server { location / { proxy_pass http://java-app; proxy_set_header Host "example.com"; proxy_next_upstream error http_502; } } }
By using this method, your backend servers don't need to worry about the DNS. Only Nginx will have the DNS records pointed to it. Your backend servers will just have to worry about dealing with the incoming traffic, and if primary-server
dies... secondary will take over!
By adding the host header in there, your backend servers can still match on the "host" header in their code too. :)

Reverend Tim
- 879
- 8
- 14
-
thnx for help i managed to create it, but now nginx is my single point of failure, i know it is easily possible to create master/slave with e.g keepalive, but how nginx backup will know about domains since all of them are registered on master, any suggestion ? thnx a lot! – vladeli Sep 01 '17 at 18:43
-
@vladeli If you are using a cloud set up, one of the built in load balancers will work fine. alternatively Keepalived is a good idea. Just bear in mind that with Keepalived, you'll need to have both servers reside in the same subnet. – Reverend Tim Sep 04 '17 at 07:39
-
real problem is when i switch to backup nginx it will not work since all domains are registered for master nginx instance and i am afraid that this setup is not possible.. – vladeli Sep 04 '17 at 08:09
-
@vladeli - what do you mean 'the domains are registered for master' ? domains should just be pointing to an IP address, and that IP address can move. Like you said, keepalived is a good idea. You can 1-1 NAT an external ip to say, 10.0.0.1, and then float that IP between two Nginx instances using keepalived. – Reverend Tim Sep 05 '17 at 07:39
-
yes all domains point to one IP, is there possibility to automate this IP change with NAT 1-1 with floating or i must do it manually ? – vladeli Sep 06 '17 at 11:35