Is it possible to enable load balancing between two servers with a third server as a backup?
Something like lb_policy round_robin but with N number of upstream.
For example, it would be great to specify the first two upstreams, then use the last one when the first two upstreams are unavailable: lb_policy round_robin 2.
Why?
In our case, we have a third server as a backup, but the processing power of this server is worse than the first two production-grade servers. We want to load balance between the first two servers to ensure the best performance.
Hmm. Good question. That is tricky. Not something we’ve considered before.
I think you could do it like this, kinda awkward though:
example.com {
reverse_proxy node1 node2 {
lb_policy round_robin
# make sure you have health checks enabled
# otherwise the nodes will never be marked unhealthy
}
handle_errors {
@proxyErr `{err.status_code} in [502, 503]`
reverse_proxy @proxyErr node3
}
}
If all the upstreams are unavailable (503) or failed to connect (502) then it will proxy to node3.