Configure HTTP load balancer with HAProxy on Debian 7

HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for very high traffic web sites and powers quite a number of the world’s most visited ones. Over the years it has become the de-facto standard opensource load balancer, is now shipped with most mainstream Linux distributions, and is often deployed by default in cloud platforms


Make sure you have installed webserver and working fine

Install HAProxy on Debian

create a new file called “backports.list” in /etc/apt/sources.list.d

#cd /etc/apt/sources.list.d

#vi backports.list

Add the following lines

deb wheezy­backports main

Save and exit the file

Update the source list and install HAProxy

# apt­ get update

# apt ­get install haproxy

Configure HAProxy

In this tutorial, we assume that there are two HTTP web servers up and running with IP addresses and We also assume that the load balancer will be configured at a server with IP address configuration file located at /etc/haproxy/haproxy.cfg.

First we need to backup the the existing config

# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.orig

# cat /dev/null > /etc/haproxy/haproxy.cfg

Add the following configuration

log local0
log local1 notice
maxconn 4096
user haproxy
group haproxy

log global
mode http
option httplog
option dontlognull
retries 3
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000

listen webfarm
mode http
stats enable
stats uri /haproxy?stats
stats realm Haproxy\ Statistics
stats auth haproxy:stats
balance roundrobin
cookie LBN insert indirect nocache
option httpclose
option forwardfor
server webA cookie node1 check
server webB cookie node2 check

and now we need to ENABLE the haproxy in /etc/default/haproxy

# vi /etc/default/haproxy

and set ENABLE=1

to start haproxy just run:

# service haproxy start

HAproxy Statistics

In this configuration we enable the statistics of haproxy, you can acsses from you browser by enter

The user and the password is like you type in the configuration in “stats auth haproxy:stats”

Sponsored Link

One thought on “Configure HTTP load balancer with HAProxy on Debian 7

Leave a comment

Your email address will not be published. Required fields are marked *