How To Install HAProxy on Ubuntu 18.04 LTS

Install HAProxy on Ubuntu 18.04 LTS

In this tutorial, we will show you how to install HAProxy on Ubuntu 18.04 LTS. For those of you who didn’t know, HAProxy is a free HTTP/TCP high availability load balancer and proxy server. It spreads requests among multiple servers to mitigate issues resulting from a single server failure. HA Proxy is used by a number of high-profile websites including GitHub, Bitbucket, Stack Overflow, Reddit, Tumblr, Twitter, and Tuenti, and is used in the OpsWorks product from Amazon Web Services.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation HAProxy on an Ubuntu 18.04 bionic beaver.


  • A server running one of the following operating systems: Ubuntu 18.04, and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install HAProxy on Ubuntu 18.04 LTS Bionic Beaver

Step 1. First, make sure that all your system packages are up-to-date by running the following apt-get commands in the terminal.

sudo apt update
sudo apt upgrade

Step 2. Network Details.

To install and configure HAProxy load balancer on Ubuntu 18.04 we will consider three systems as follows:

Web Server Details:
  Server 1:
  Server 2:
HAProxy Server: 
  HAProxy:     haproxy  

Step 3. Installing HAProxy on Ubuntu.

At first, we will install HAProxy by executing the below commands:

sudo add-apt-repository ppa:vbernat/haproxy-1.7
sudo apt update
sudo apt install haproxy

Step 4. Configuring HAProxy.

Now edit HAProxy default configuration file /etc/haproxy/haproxy.cfg and start configuration:

nano /etc/haproxy/haproxy.cfg

At the end of the file we will add the following information:

frontend Local_Server
mode http
default_backend webserver

backend webserver
mode http
balance roundrobin
option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
option httpchk HEAD / HTTP/1.1rnHost:localhost

To verify the configuration:

sudo haproxy -c -f /etc/haproxy/haproxy.cfg

If the above command returns output as “configuration file is valid” then restart the HAProxy service:

systemctl restart haproxy

Step 5. Accessing HAProxy.

With the HAProxy configured and running, open your load balancer server’s public IP in a web browser and check that you get connected to your backend correctly. The parameter stats URI in the configuration enables the statistics page at the defined address:

Congratulations! You have successfully installed HAProxy. Thanks for using this tutorial for installing the HAProxy load balancer in Ubuntu 18.04 bionic beaver system. For additional help or useful information, we recommend you to check the official HAProxy website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button