Installing HAProxy 1.7 on Debian 9.1 Linux Dedicated Box


HAProxy is a social networking software application which offers a high availability, load balancing as well as proxying for the TCP and the HTTP network applications. This software application is best suited for high traffic website and it has many popular websites across the internet. Here it will be shown to you on how to install as well as configure the HAProxy on Debian 9.1 linux dedicated servers.

HAProxy is having many prominent features, here it will be focused on how to setup the HAProxy to “proxy” the web application on Linux Dedicated Server.

best dedicated server providers in Chennai    windows dedicated server providers in Chennai


Installation Process of HAProxy

Here the Debian 9 will already be having the ships with HAProxy on Linux Dedicated Server as it can be used for simply using it and installing it under the apt-get:

# apt-get update
# apt-get install haproxy

If the commands that have been used is successful, then you will be having an installed HAProxy as it can be proceeded to the next step.

Here the HAProxy configuration file is split up in the two sections - “global” and “proxies”. Here one will be dealing with the process-wide configuration while the latter consisting of the default configuration while the latter will be consisting of the default configuration, front end as well as backend sections.

By usage of the favorite text editor, open /etc/haproxy/haproxy.cfg and the notice predefined sections: “global” as well as “defaults”. Here the first thing that you would want is to increase the maxconn to good size, as it will affect the connections that HAProxy is allowing. Here a lot of connections can cause the web service to crash mainly due to many requests. You will be required to adjust the size to check if its working or not. Here in the global section there is a chosen maxconn value of 3072.
maxconn 3072

Now, in the default section, you need to add the following line under mode http:

option forwardfor

Here it will add the X-Forwarded-For headers in each of the request, which will allow the backend servers in learning the original IP address of the user.

Here one needs to add this line in enabling the HTTP connection-close mode which is on the server side this will keep the ability in supporting the HTTP keep alive on the client side. This will reduce the latency on the client side and will help in conserving the server resources.
If you are looking to keep alive both the clients as well as the server sides, then one should choose the option http-keep-alive. This is very useful when the cost of connecting to the new server is much more than the cost of retrieving the requested resources.

Here the resulting config file will be looking as:

mode http
option forwardfor
option http-server-close
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms


best Linux dedicated server in Chennai


For setting up the proxy, you will be required to add the two sections to the configuration file in defining the two parts of the proxy: the front end as well as the backend.

Here the front end will be handling the HTTP connections. By adding the following at the end of the haproxy.cfg file:

frontend http-frontend
bind public_ip:80
reqadd X-Forwarded-Proto:\ http
default_backend wwwbackend

Backend Configuration

One must be sure of replacing the public_ip with the servers with the servers public IP address or the domain name.

One needs to setup the backend by adding the following lines to the end of the configuration file:

backend wwwbackend
server 1-www server1_ip:80 check
server 2-www server2_ip:80 check
server 3-www server3_ip:80 check

Here the backend configuration which has been used here is to create the 3 connections which is named as X-www. Each of it will correspond to the serverX_IP. This will be allowing the load balancing between each of the server in the specific server set. For checking the option makes the load balancer perform health checks on the server.

One needs to save the configuration file and then restart the HAProxy:

service haproxy restart

Now if everything has been working then you will be able in connecting to the http://public_ip/ and then view the website.

Debugging of the Errors

If the HAProxy instances is not able to start after the modification is performed, then there are chances that you will be having the error which is somewhere in the configuration file. For getting clear messages about the issues that are in the configuration file, then you will be able to start the HAProxy manually by using the command.

# haproxy -f /etc/haproxy/haproxy.cfg