This project demonstrates the use of HAProxy as a reverse proxy and load balancer to route traffic based on domain name. It serves two React frontend applications running on separate virtual machines.
-
VM1: 192.168.232.110: (HAProxy - Reverse Proxy)
-
VM2: 192.168.232.111:3000 green-app.com React App
-
VM3: 192.168.232.113:3000 white-app.com React App
git clone https://github.com/croyce97/HAproxy_project.git
sudo apt update -y
sudo apt install npm
- On VM2:
sudo vi HAproxy_project/src/index.css
In the .square { ... } block, replace line background: var(--white); with background: var(--green);.
cd ..
cd HAproxy_project
npm start
- On VM3:
cd HAproxy_project
npm start
-
Visit: http://192.168.232.111:3000
-
Visit: http://192.168.232.113:3000
sudo apt update
sudo apt install haproxy -y
sudo vi /etc/haproxy/haproxy.cfg
- Copy haproxy_reverse_proxy.conf into this file.
Local Windows Machine:
- Open Notepad as Administrator
- Open the file:
C:\Windows\System32\drivers\etc\hosts - Add:
192.168.232.110 white-game.com green-game.com
sudo systemctl restart haproxy
sudo systemctl enable haproxy
Visit: http://green-game.com Image: green-game.com
Visit: http://white-game.com Image: white-game.com
-
VM1: 192.168.232.110: canhnq.com (HAProxy - Load Balancer)
-
VM2: 192.168.232.111:3000 React App
-
VM3: 192.168.232.113:3000 React App
git clone https://github.com/croyce97/HAproxy_project.git
sudo apt update -y
sudo apt install npm
cd HAproxy_project
npm start
-
Visit: http://192.168.232.111:3000
-
Visit: http://192.168.232.113:3000
sudo apt update
sudo apt install haproxy -y
sudo vi /etc/haproxy/haproxy.cfg
- Copy haproxy_load_balancing.conf into this file.
VM1:
sudo vi /etc/hosts- Add
127.0.0.1 canhnq.com
Local Windows Machine:
- Open Notepad as Administrator
- Open the file:
C:\Windows\System32\drivers\etc\hosts - Add:
192.168.232.110 canhnq
sudo systemctl restart haproxy
sudo systemctl enable haproxy
Visit: http://canhnq.com Image: canhnq.com
Visit: http://canhnq.com:8405/stats with username: admin, password:admin123 to monitor. Image: canhnq.com:8405/stats