How to implement failover of UDP traffic based health checks with HTTP response codes?

Viewed 52

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 nginx VPS servers. One primary and one backup.
  • I have two WireGuard VPS servers. One primary and one backup.
  • Failover IP which will be moved by keepalived to a backup nginx load-balancing server if the primary nginx server fails
  • keepalived will monitor the primary and backup nginx servers
  • I have a script that responds with an HTTP code on each WireGuard server at / and port 8080 about the status of WireGuard, such as http 200.
  • Based on the HTTP health checks, I would want nginx to pass WireGuard's udp packets to the primary WireGuard server, or if the primary server is problematic (based on http codes), I would need to pass the udp packets to the backup WireGuard server
  • I would also need to pass the udp traffic, such that the traffic is returned from the failover_ip of the nginx server, and not from the ip of the WireGuard VPS server.

I went through this article and what I'm not sure of is:

  • How do I setup the HTTP checks? I added the backup flag 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?
0 Answers
Related