I have added the following to nginx.conf.
stream {
upstream wg_servers {
server wg_ip_#1:51820;
server wg_ip_#2:51820 backup;
}
server {
listen failover_ip:51820 udp;
proxy_pass wg_servers;
proxy_bind failover_ip:51820;
#location / {
# proxy_pass http://wg_servers;
# health_check port=8080;
#}
}
}
Basically, what I am trying to achieve is as follows:
- I have two
nginxVPS servers. One primary and one backup. - I have two
WireGuardVPS servers. One primary and one backup. - Failover IP which will be moved by
keepalivedto a backupnginxload-balancing server if the primarynginxserver fails keepalivedwill monitor the primary and backupnginxservers- I have a script that responds with an HTTP code on each
WireGuardserver at/and port8080about the status ofWireGuard, such ashttp 200. - Based on the HTTP health checks, I would want
nginxto passWireGuard'sudppackets to the primaryWireGuardserver, or if the primary server is problematic (based onhttpcodes), I would need to pass theudppackets to the backupWireGuardserver - I would also need to pass the
udptraffic, such that the traffic is returned from thefailover_ipof thenginxserver, and not from the ip of theWireGuardVPS server.
I went through this article and what I'm not sure of is:
- How do I setup the HTTP checks? I added the
backupflag to the secondary server, but how do I do the checking? - Is there anything else I should add/remove to make it more effective for my goals?