Load Balancer for Spotter Web using Ubuntu Server and HAProxy

This option is viable when there is a high number of users and a need to load balance Spotter Web tasks for multiple servers. The load balancer automatically selects the next suitable server for the user and handles the traffic flow by itself.

The certificate is installed on Ubuntu Server, and HAProxy uses it to secure communication.

In this example, we go through the Load Balancer installation using HAProxy on the Ubuntu Server LTS operating system (e.g., Ubuntu 24.04.4 LTS or newer).

Configuration

To proceed, you need to have Ubuntu Server installed and updated with the latest patches.

When this is done, you can make an SSH connection to the Ubuntu Server.

  1. To install HAProxy, you run the following command:

sudo apt install haproxy -y
  1. Enable HAProxy to run automatically using the following command:

sudo systemctl enable haproxy
  1. Make a backup of the original HAProxy configuration:

sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
  1. Edit the HAProxy configuration using this command:

sudo nano /etc/haproxy/haproxy.cfg
  1. Change the defaults-section current timeout values for these and add the missing ones:

timeout connect 5s
timeout client 24h
timeout server 24h
timeout tunnel 24h
  1. Add this example configuration at the end of the file and change the backend server details:

# HTTPS (Port 443)
frontend https_front
    bind *:443 ssl crt /etc/haproxy/certs/site.pem
    mode http
    default_backend https_back

# Spotter Web Servers Configuration
backend https_back
    mode http
    balance roundrobin
    cookie SRV insert indirect nocache maxidle 24h maxlife 7h
    option httpchk GET /
    http-check expect status 200
    default-server inter 5s fall 3 rise 2
    server web1 server1IP:443 ssl verify none check cookie web1
    server web2 server2IP:443 ssl verify none check cookie web2

# HAProxy Stats Page
listen stats
    bind *:8404
    mode http
    stats enable
    stats uri /
    stats refresh 5s
    stats auth admin:password
  1. Save the configuration file, and then you can ensure that the configuration is valid using the command:

sudo haproxy -c -f /etc/haproxy/haproxy.cfg
  1. If the configuration is valid, you should get a message:

Configuration file is valid
  1. Now you can restart HAProxy using the command:

sudo systemctl restart haproxy
  1. Lastly, you need to open ports for the Ubuntu firewall if that is in use, using the commands:

sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 8404

Now you can test forming a connection to the HAProxy stats page to see if the system works as it should and can communicate with the backend servers.

You can access the HAProxy stats page using the server IP address or domain name and port 8404 (Example: http://serverip:8404).

After this, you can make a connection to the site and check that Spotter Web is working as it should, and monitor the stats page to ensure that load balancing works as it should.