How to route hosts to different backends

This guide well explain how to use the Balancer to send different hostnames (host headers) to different backends (servers).

This is done using the ACL system in Snapt, a frontend and at least two backends. It’s commonly called host based routing.

In our example we will be sending www.snapt.net to a set of servers, and dev.snapt.net to a single server. This will mean a frontend to listen on port 80, and two backends with servers in them.

Creating the Backends

The first step is to add your two (or more) Backends under Backend Management. These will be where we will send traffic based on the ACLs. You can direct traffic based on the host header from a frontend to a backend. As discussed for us this is Production (www.snapt.net) and Development (dev.snapt.net).

Remember when adding your frontends and backends that they must all be in HTTP mode in order to redirect. We have the following configuration:

Production: 192.168.0.100:80 , 192.168.0.101:80

Development: 192.168.0.200:80

Creating the ACL

Next up we are going to create the ACL object to match “dev.snapt.net”. We only need that, as we will use Production as a “Default Backend”.

Go to Balancer -> ACL Management and Add a new ACL, ours will be called “Dev” and set Template to None.

Choose “hdr(host)” as the Match Criterion, with a Match Operator of Plain. Then set the value to “dev.snapt.net”. This is saying to look for dev.snapt.net in the Host portion of the header.

Creating the Frontend

Now add a frontend under Frontend Management. As you can see in our Frontend we have set Production as the default backend and set it to HTTP mode.

Save this and then click the Attach ACL option on Frontend Management next to your new Frontend.

Attach an ACL

Now we want to tell it to use the backend Development, if the ACL “Dev” is true. Save this and you are all done!