Managing Web Traffic Load With HaProxy

HaProxy is used to decrease the web application server load. It also used to decrease the database server load. It can handle a lot of traffic. Similar to nginx, but nginx can’t handle the ip/tcp traffic it is used only for web traffic. It use low memory to handle large number of concurrent request.


We will install latest version of HaProxy ( 1.5.1 ) on our ubuntu server,  for HaProxy latest version installation we will use pp:vbernat/haproxy-1.5 repository .

#add-get-repository –y pp:vbernat/haproxy-1.5

#apt-get update

#apt-get install  haproxy –y

If add-get-repository not found than install software-properties-common package

HaProxy Configuration

Before going to configure we will need to know about some options.

Fronted :- HaProxy listen all connection here

Backend: -HaProxy forward all incoming request

Stats :- Show status of all connected load balancer nodes .

Algorithms Of Load Balancing

HaProxy use round-robin algorithm by default.

Roundrobin:-  All coming request will distribute amongst all connected nodes  one buy one. For session based application you will need configure sticky session. Using sticky session HaProxy will send client request on same server . So you will need to define cookie COOKIES –NAME prefix into back-end directive.

Static-rr :- Work same as round-robin but we can’t adjust server  weights. It is used for long running connection .

Leastconn :- HaProxy will send the connection on node which have lowest connection.

Other one is uri but it is not used more.

Configuration Example

mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except
option redispatch
retries 2
timeout http-request 10
timeout queue 75400
timeout connect 75400
timeout client 75400
timeout server 75400
timeout http-keep-alive 25
timeout check 15
maxconn 40000
# frontend LB 
reqadd X-Forwarded-Proto:\ http 
default_backend LB
backend LB
mode http
stats enable 
stats hide-version 
stats uri /stats 
stats realm Haproxy\ Statistics 
stats auth haproxy:redhat # User and Password for HaProxy status page. balance 
roundrobin # Blancing algorithm. 
option httpchk 
option httpclose 
option forwardfor 
cookie SESSION insert 
server app1-srv cookie app1-srv check # backend server. 
server app2-srv cookie app2-srv check # backend server. 
server app3-srv check backup # backup server if app1 and app2 down.

Save and exit.

Now restart HaProxy service.

#service haproxy restart
#chkconfig haproxy on

HaProxy server is ready to handle all incoming traffic.We can check the HaProxy nodes status with it’s status page.

Type in your browser and type the credential.User : ha proxy , Password : [email protected].

Make sure port 80 should be open in firewall.


Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment