One Load Balancer Per Domain?

February 23, 2018 1.1k views
Load Balancing Networking

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

2 Answers
asb MOD March 1, 2018
Accepted Answer

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.

Have another answer? Share your knowledge.