- Ubuntu Server
- Any custom Service. In our example, we will forward the port 8080 request to other server.
We are gonna explain on how to install haproxy on Ubuntu server. Additionally, we will show up on how to configure service which forwards a requests from haproxy to specific service.
Lets install haproxy on the server.
apt-get install haproxy
Start the service and enable the service on system startup.
systemctl start haproxy
systemctl enable haproxy
We don’t make any changes on default settings. This post uses all the default haproxy values.
Open haprxoy configuration and add the below mentioned lines. This will forward the request from port 8080 request to server xx.xx.xx.xx port 8080
listen nameapp 0.0.0.0:8080 mode http balance roundrobin server server1 xx.xx.xx.xx:8080 check
The above configuration forwards the port 8080 request from haproxy server to xx.xx.xx.xx.
balance roundrobin – This is used to balance the traffic between multiple servers incase multiple server added
Restart the service to make into effect.
systemctl restart haproxy
Access the page using the port number on the browser and you can see the traffic will be routed to server1.