There are several possibilities.
One option is to use the Common Address Redundancy Protocol or carp. The following is a brief description on the manual page.
"carp allows multiple hosts on the same LAN to share a set of IP addresses. Its main purpose is to ensure that these addresses are always available, but in some configurations the carp can also provide load balancing functionality.
It should be possible to adjust IP address balancing so that if the primary or primary http service fails, the secondary or backup http service becomes the master. carp is host oriented, not application centric. Therefore, when the http service goes down, it also needs to remove the network interface for the carp to do its job. This means that you will need more than one IP address to log in and perform maintenance. You will need a script to complete the next steps after the original service returns to the network.
The second option is to use nginx. This is probably better for what you are trying to do.
Many years ago, I needed something similar to what they were trying to do, and I ended up hacking something that did it. In fact, it was a switch. When “A” fails, switch to “B”. The re-synchronization process was to take time stamped logs from “B” and play them back to “A” once “A” was online again.
source share