Search code examples
google-cloud-platformsubdomainload-balancing

How to map subdomain name to GCP https load balancer


I create a group with 6 instances on GCP and use the GCP load balancer(LB). I use nginx with Let's encrypt, and all websites have to use https.

My condition as shown below.

server 1 : x11.abc.com(LB dns: x1.abc.com), x31.abc.net(LB dns: x3.abc.net)
server 2 : x12.abc.com(LB dns: x1.abc.com), x32.abc.net(LB dns: x3.abc.net)
server 3 : x13.abc.com(LB dns: x1.abc.com), x33.abc.net(LB dns: x3.abc.net)
server 4 : x21.abc.com(LB dns: x2.abc.com), x34.abc.net(LB dns: x3.abc.net)
server 5 : x22.abc.com(LB dns: x2.abc.com), x35.abc.net(LB dns: x3.abc.net)
server 6 : x23.abc.com(LB dns: x2.abc.com), x36.abc.net(LB dns: x3.abc.net)

But when I test, x1.abc.com shows the contents of x11 ~ x13 and x21 ~ x23, and x3.abc.net shows the content of x31 ~ x36, BUT x2.abc.com shows the request url was not found.

I want to x1.abc.com shows the contents of x11 ~ x13, x2.abc.com shows the contents of x21 ~ x23, and x3.abc.net shows the contents of x31 ~ x36.

How do I setup the GCP load balancer?


Solution

  • The following suggestions you can follow to setup the load balancer:

    • Instead of having only one backend service with only instance group containing all backend instances, you can group instances based on each traffic type. Each instance group will contain instances hosting the same content. Following that you have to configure host and path rules accordingly.

    This is one way to create an HTTP(S) load balancer that distributes traffic to different instances based on the path in the request URL (check configure host and path rule section ).

    • You can also think of using multiple SSL certificates when you are serving from multiple domains using the same load balancer IP address and port, and here you can use a different SSL certificate for each domain. You must specify at least one SSL certificate for each of these resources and you can specify up to ten.