How Can We Help?
Web Servers with HAProxy for Failover
Two web servers will be load-balanced using HAProxy.
Prerequisites
- Two web servers with static IPs.
- HAProxy installed on a load balancer server.
Step-by-Step Guide
Step 1: Install Apache or Nginx on Web Servers
1. Install Apache or Nginx:
sudo apt install apache2 -y
Step 2: Install and Configure HAProxy on the Load Balancer
1. Install HAProxy:
sudo apt install haproxy -y
2. Configure HAProxy:
sudo nano /etc/haproxy/haproxy.cfg
HAProxy Configuration:
frontend http_front
bind *:80
default_backend web_servers
backend web_servers
balance roundrobin
server web1 <WEB1_IP>:80 check
server web2 <WEB2_IP>:80 check backup
3. Restart HAProxy:
sudo systemctl restart haproxy
Step 3: Verify HAProxy Load Balancing and Failover
1. Shut down one of the web servers to confirm that traffic fails over to the other.