Load balancers

A load balancer runs nginx on one of your servers and spreads traffic across several backends. Add a second load balancer server and a floating IP for high availability.

Create a load balancer

  1. Open Load balancers.
  2. Fill in: Name; the Load balancer server (where nginx runs); the Listen port (80, or 1024 to 65535); the Algorithm; optional Hostnames (comma separated); and a Health check path.
  3. Choose backends: tick servers, add Other addresses if needed, and set the Backend port (default 3000).
  4. Click Create load balancer.
AlgorithmUse it when
Round robinBackends are alike. The default choice.
Least connectionsRequests vary a lot in how long they take.
Client IP hash (sticky)A client should keep hitting the same backend.

Health checks and backends

On the load balancer's page you can set the health check type (HTTP or TCP), the path, how many Failures mark a backend down (default 3) and the Interval in seconds (default 10).

Each backend has a weight (1 to 100) and a state:

  • Ready: receives traffic.
  • Drain: finishes current connections, gets no new ones. Use it before maintenance.
  • Maintenance: out of rotation.

Click Add backend to add more. The page also shows the generated nginx configuration.

High availability

Without HA, the load balancer server is a single point of failure. To remove it:

  1. Set Second Load Balancer Server, Cloud Provider and Floating IP (all three are needed). The cloud provider must be connected under Settings → Cloud providers.
  2. Click Enable HA Pair.
  3. Point your DNS at the floating IP, not at either server.

If the active server fails, the floating IP moves to the other one in about 30 seconds. Fail Over to … moves it by hand, for example before maintenance.

Deploy to several servers

In a project's Deploy Target card, choose Several Servers, pick the Target Servers and the Load Balancer, and click Save Deploy Target. Deploys then roll out to each server in turn.

HTTPS at the load balancer

When a project deploys behind a load balancer, its verified custom domains get their certificate on the load balancer itself: the LB answers HTTPS for those hostnames, redirects plain HTTP to HTTPS and forwards to the servers over HTTP. For this the load balancer must listen on port 80 and either list the hostname or have no host list. On an HA pair both servers get the certificate.

Limitations

  • nginx is the only engine (no HAProxy).
  • A removed domain stays on the load balancer until its next apply (any edit or Re-apply).
  • The health probe sends no Host header; use a TCP health check for backends that route by hostname.