One Load Balancer Per Domain?

February 23, 2018 3.9k views
Networking Load Balancing

I am pretty sure I know the answer, but I can only load balance a single domain name on a DO loadbalancer?

3 Answers

Multiple domains could potentially be pointed at one load balancer instance. Though there is only one IP address per load balancer. That means that the Droplets behind the load balancer will each need to be able to understand how to respond based on the domain being requested.

A simple example of this would be two static sites being served by Nginx. Each Droplet behind the load balancer would need to serve both sites and Nginx would need to use named server blocks to know which site to serve for which request. A minimal example of what that would look like:

server {
        listen 80 default_server;
        server_name example.com;
        root /var/www/html;
        index index.html;

        location / {
                try_files $uri $uri/ =404;
        }
}

server {
        listen 80;
        server_name blog.example.com;
        root /var/www/blog;
        index index.html;

        location / {
                try_files $uri $uri/ =404;
        }
}

Then you would need to create A records for both example.com and blog.example.com pointing to the IP address of the load balancer. The load balancer passes the host request straight through to the Droplets, allowing them to decide how to respond.

by Justin Ellingwood
When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server. In this guide, we'll discuss how to configure server blocks in Nginx on an Ubuntu...

Thank you very much for your detailed response. very happy to be wrong in this case. I was quite sure it was “yes, 1 lb for each domain).... thanks again, i am now sure i want to go with DO load balancer.

Digital Ocean load balancer is very basic. It can only do one domain SSL using Let’s Encrypt. Just trying to add MORE ssl certs for one load balance suing multiple domains is impossible. For $10 that a bit expensive.

Your only option is to make the load balancer yourself using Nginx and Certbot. The Certbot will use Let’s Encrypt to automatically renew the certs.

As for the web back end you will need to learn Nginx with multiple virtual hosts using port 80.

Digital Ocean has a very nice article on how to create your own Nginx with SSL cert using Let’s Encrypt here:
https://www.digitalocean.com/community/tutorials/how-to-set-up-let-s-encrypt-with-nginx-server-blocks-on-ubuntu-16-04

In AWS one load balancer (ALB) cost $15 can handle up to 50 domains (hard limit) and each domain can have its own SSL certificate from Cert manager which auto renews cert using AWS cert authority instead of Let’s Encrypt which is not trusted in many high level companies such as Shopify (web hooks). So depends on your needs you have 3 options.

by Hazel Virdó
In this tutorial, you will use Certbot to obtain a free SSL certificate for Nginx on Ubuntu 16.04 and set up your certificate to renew automatically. This tutorial will use a separate Nginx server block file to maintain the default file as a fallback configuration as intended.
Have another answer? Share your knowledge.