Routing options by hostname with iRules, NGINX, and Distributed Cloud

Someone is working on a Distributed Cloud configuration and had the following question:

I have defined multiple hostnames on a single XC HTTP LB.

  • a.b.com
  • c.b.com
  • x.y.com

How do i forward a request to a different origin based on the hostname?

With an iRule I'd interpret this question to be "on a single virtual server" and the solution would be something like this:

when HTTP_REQUEST priority 500 {
    switch -- [HTTP::host] {
        "a.b.com" {
            pool ab-pool
        }
        "c.b.com" {
            pool cb-pool
        }
        "x.y.com" {
            pool xy-pool
        }
    }
}

With NGINX, you could use a host-to-upstream mapping like below (not a complete config):

map $host $backend_upstream {
    default       "";
    a.b.com       ab-pool;
    c.b.com       cb-pool;
    x.y.com       xy-pool;
}
server {
    listen 80;
    location / {
        proxy_pass http://$backend_upstream;
        proxy_set_header Host $host;
  }
}

In Distributed Cloud, the solution would be to create an L7 route on the HTTP load balancer for each host. Here's an example for the a.b.com one, all three would follow the same steps.

1. Edit the configuration of your HTTP Load Balancer and click Configure.

2. Set the route fields as shown and click Add Item within the Headers block.

3. Set the header name to Host with an exact value of a.b.com.

4. Finally click Add Item within the Origin Pools block and add your origin pool accordingly.

Once that route is added, you can repeat the same steps for c.b.com and x.y.com.

One challenge, three platforms, three solutions. Wouldn't it be something if we could change that 1:3:3 ratio in the previous sentence to a 1:3:1 scenario? Hmm... 

Published Apr 04, 2025
Version 1.0
No CommentsBe the first to comment