HAproxy is a software allowing Load-Balancing between several web servers by allocating requests in an almost transparent way for the user.


There are three necessary machines at least : one HAproxy server and two web servers in which incoming requests will be allocated.
In both web servers, there is a need to make apache2 operational at least, each having access to an identical content (in order to avoid displaying two versions of the web site.)

The server HAproxy acts as a bridge between the web servers network and the external network. It has to dispose of 2 network interfaces : one to cope with incoming requests and the other to communicate with the various servers of the cluster.

In our example, the server HAproxy would have as “external” IP (frontal web) and as “internal” IP (web servers network)

Web servers’ IP are:

Implementation of Load-Balancing

Here are the steps to follow in order to install and launch the server HAproxy to implement Load-Balancing.

We change the name of the machine HAproxy:

You might also want to think about changing its name in /etc/hosts:

Install the service HAproxy :

For HAproxy to be entirely considered as a service :

Now we are going to set up a file of basic confguration to test in our two web servers.

Another Load-Balancing mode can be used :
– mode “leastconn” : the server having had the least connections will first answer requests.

Client-server lasting connection

Some customs need a persistent connection between client and server (sessions management, shopping cart on e-commerce).
To cope with this issue, we can send a cookie to the user.
According to the cookie content, the Load-Balancing set up can transfer the requests in the matching server and the client could maintain lasting exchanges with this one.

All you need is to add these lines :

To check on the cookies presence and their actions on a Firefox browser : Option > Private life > Cookies display

Logs et stats

It is possible to view the servers’ Load-Balancing thanks to HAproxy web interface.

The HAproxy interface of general information includes many informations about different web servers functioning and about the Load-Balancing state.

To consult these information, you just need to type the following URL :


Categories: SystemTutorials

JN Community

Les Ressources, en particulier les tutoriaux, présupposent que l’Utilisateur qui décide de les mettre en œuvre dispose des connaissances, des compétences et de l’expérience nécessaire pour cette mise en œuvre. L’Utilisateur disposant d’une connaissance, compétence et/ou expérience limitée ou insuffisante doit absolument s’abstenir de mettre en œuvre les Ressources par lui-même. Jaguar Network décline toute responsabilité quant aux conséquences dommageables de la mise en œuvre des Ressources, notamment sur les infrastructures informatiques de l’Utilisateur, de ses commettants ou préposés ou de tout tiers. Il est précisé en tant que de besoin que toute intervention de Jaguar Network visant à réparer les dommages causés par la mise en œuvre des Ressources par un Utilisateur ne disposant pas des connaissances, compétences et/ou expériences suffisantes sera facturée et fera l’objet d’un devis préalable et d’un bon de commande aux conditions des contrats Jaguar Network en vigueur.

Related Posts


Installation of a web server LEMP (Linux, Nginx, MySQL, PHP)

Vote The installation of a server LEMP Linux + Nginx + MySQL + PHP might be more useful and efficient than an Apache (server LAMP). Articles similaires


10 tips to write efficient scripts on Linux

Vote The shell script is the most simple type of programming you would write on Linux. Moreover, it is a necessary skill to automate your system administration tasks, to develop new simple features, … In Read more…


Use VIM text editor

Vote In a production environment, Linux is generally installed in mode console and is command line administered. That is why it is essential to edit files in a command line way, and one of the Read more…