UPCOMING EVENT

Let's Meet during iFX EXPO International 2024 in Limassol, Cyprus (18-20 June)

Book a Meeting
  • +357 2425 0808
  • Login
  • English

Home

Blog

How To Install HAProxy on Debian 11 Serv...

How To Install HAProxy on Debian 11 Server

How To Install HAProxy on Debian 11 Server

NetShop ISP

NetShop ISP · Blog Author

Aug 07, 2023 · Technical Tutorials

HAProxy is a high-performance, open source load balancer and reverse proxy for TCP and HTTP-based applications. Using HAProxy, one can distribute workloads and improve the performance of websites and web-based applications with faster response times, higher availability and increased throughput.

HAProxy, when combined with DNS Geolocation Diversion, can load balance the traffic to your website/application so users from different areas of the world will be served from a regional HAProxy server and the request will then be forwarded to a backend server (e.g. another web server or a database).

The advantage in this kind of setup is that you can avoid the bottleneck of a single web server handling all the requests & traffic by itself. Secondly, by combining a web farm of HAProxy instances with DNS Geolocation is that you can serve different content or rules to specific regions of the world, as per your business requirements.

In this article we will demonstrate how to easily setup HAProxy on a Debian 11 Server with the basic configuration, which you can then optimize or extend as per your bespoke requirements.

Steps to Install HAProxy on Debian 11

HAProxy is pretty useless when used in one server. So in this example we will install it on two Debian servers which we will then configure with roundrobin balancing.

Any command you see further below must be executed on both/all of your servers.

Step 1 – Update System

Execute the following command to install and use the latest available software packages on your Debian system.

root@localhost:~$ apt update -y
root@localhost:~$ apt upgrade -y

Once completed, reboot the server as follows:

root@localhost:~$ reboot
or
root@localhost:~$ shutdown -r now

Step 2 – Install Apache (optional)

This step is optional as you may want to use HAProxy without Apache. However, for the purpose of demonstrating the successful installation and usage of HAproxy we will install and configure Apache as follows.

root@localhost:~$ apt -y install apache2

Once apache2 is installed, run the following command to insert a pre-defined message in index.html. This will help us understand the HAProxy server that is used every time we will be refreshing our domain.

Server 1:

root@localhost:~$ echo "Server1 says Hello" | sudo tee /var/www/html/index.html

Server 2:

root@localhost:~$ echo "Server2 says Hello" | sudo tee /var/www/html/index.html

Step 3 – Install and Configure HAProxy on Debian 11

Run the following command on both servers to install haproxy:

root@localhost:~$ apt install haproxy -y

Now, lets configure HAproxy to use the roundrobin balance mode between the two servers.

Open the file /etc/haproxy/haproxy.cfg and insert the following configuration. Then save and close your file.

frontend haproxy_apache_front
        bind *:80

        default_backend    haproxy_apache_backend

        option             forwardfor
  

backend haproxy_apache_backend                                                                                                                     
        balance            roundrobin

        server             backend01 10.10.10.111:80 check
        server             backend02 10.10.10.112:80 check

Now, restart the haproxy on both servers as follows:

root@localhost:~$ systemctl restart haproxy

Let’s test our creation! For the purpose of this tutorial, our Apache configuration was setup with vhost “haproxy.netshop.global”.

Output from HAproxy Server 1

Then reload the page a few times and you should be seeing the message from the 2nd server. This means that HAProxy with roundrobin balance mode work!

Output from HAProxy Server 2

Success! Stay tuned for more HAProxy tutorials with advanced HTTP and TCP configurations!

Press Releases
74

Free VPS Trial

No Credit Card Required.

Recent Posts

How To Extend Root Partition using Home Partition space in CentOS

How To Extend Root Partition using Home Partition space in CentOS

30 May, 2024

NetShop ISP to Attend iFX EXPO International 2024 and Announce Global Infrastructure Expansion

NetShop ISP to Attend iFX EXPO International 2024 and Announce Global Infrastructure Expansion

23 May, 2024

TNFX Broker Partners with NetShop ISP to Offer Low-Latency Forex VPS to Traders

TNFX Broker Partners with NetShop ISP to Offer Low-Latency Forex VPS to Traders

14 May, 2024

How to Install Nginx, MySQL, PHP on Ubuntu 22.04 (LEMP)

How to Install Nginx, MySQL, PHP on Ubuntu 22.04 (LEMP)

10 May, 2024

How To Migrate from MongoDB Atlas to self-hosted Ubuntu 22.04 Server

How To Migrate from MongoDB Atlas to self-hosted Ubuntu 22.04 Server

15 April, 2024

#letushostyou

Award Winning Hosting Provider established in 2004.

120 Faneromenis Avenue, Imperial Tower, 2nd Floor, Larnaca 6031, Cyprus

Products

Bare Metal Servers

Customized Servers

Virtual / Cloud Servers

Forex VPS

Storage VPS

cPanel Web Hosting

Reseller Web Hosting

Colocation

Addons

Premium DNS

Email Hosting

Cloud Backup

DDoS Protection

Licenses

SSL Certificates

Domain Names

Premium SLAs

About Us

Data Center Locations

Looking Glass

Our Company

Contact Us

Careers in Cyprus

Become a Partner

Awards

Certifications

© 2024 S.S. NetShop Internet Services Ltd. All rights reserved.  Terms & Conditions  |  Privacy Policy
CY Reg. Number: HE 217340 | EU VAT Number: CY10217340J

Visa
Mastercard
PayPal
Revolut
Wire Transfer