Setting up a load balancer is a two step process: creating the load balancer and then adding backend Droplets.
You can create a load balancer using the Create menu at any time or use the Create load balancer button on the Load Balancers overview page.
On the creation page, you will:
Choose a datacenter region. Your load balancer and Droplets need to be in the same datacenter, so choose the one where your Droplets are or will be located.
Add forwarding rules. You need at least one rule to create a load balancer. You can either create new rules now by clicking the New Rule drop down, or accept the default route (HTTP port 80 on the load balancer to HTTP port 80 on the backend Droplets) and configure the rules you want after the load balancer has been created.
The left side of each rule defines the listening port and protocol on the load balancer itself, and the right side defines where and how the requests will be routed to the backends. You can change the protocols using the drop down menus. If you use HTTPS or HTTP2, you will also be asked to choose an existing SSL certificate, create a free certificate using Let’s Encrypt, provide custom certificate files, or use SSL passthrough.
Set advanced settings. Advanced settings allow you to modify some additional parameters for the load balancer. The defaults work well for most cases, but the options are:
Algorithm: The default round robin algorithm sends requests to each available backend in turn. The alternative least connections algorithm sends requests to the backend with the least number of active connections.
Sticky sessions: If your application’s sessions rely on connecting to the same backend for each request, you can enable sticky sessions. This sets a cookie with a configurable name and TTL (to define how long the cookie is valid) so that the load balancer can send future requests to the same server.
Health checks: The load balancer will only forward requests to Droplets that pass health checks. You can customize the criteria for the health checks or accept the default settings.
In the Target section, you choose the Protocol (HTTP or TCP), Port (80 by default), and Path (
/ by default) that Droplets should respond on.
In the Additional Settings section, you choose:
SSL: You can redirect HTTP requests on port 80 to HTTPS port 443 by enabling this option. Once you click Save, HTTP URLs will be forwarded to HTTPS with a 307 redirect.
Proxy Protocol: By default, client connection information (like IP addresses) only reach the load balancer. PROXY protocol passes this information along to the backend Droplets. Backend services need to accept PROXY protocol headers or the Droplets will fail the load balancer’s health checks.
Choose a name and create. Load balancer names must be unique and contain alphanumeric characters, dashes, and periods only. Once created, you can change the name at any time by clicking on the existing name on the load balancer page.
Your choice of Droplets will be limited to the region where the load balancer was created. You can add individual Droplets or select by using a tag. When you use a tag, only the tagged Droplets in the same region as the load balancer will be part of its pool. Only one tag can be used per load balancer.
When you’ve selected the tag or the Droplets, click Add Droplets. The load balancer will check the health of the backend Droplets. Once the backends have passed the health check the required number of times, they will be marked healthy and the load balancer will begin forwarding requests to them.