Two of LoadMaster’s less utilized features include Content Switching and Header Modification. These two HTTP/HTTPS specific features allow LoadMaster to become a valuable part of your application delivery rather than merely balancing traffic to multiple application servers.
Ordinarily, LoadMaster’s main purpose is to evenly distribute traffic to a pool of real servers. However, with Content Switching, LoadMaster takes on the role of traffic director. By examining the content of each request, traffic can be assigned to a specific server based on pattern matching. Pattern matching can be performed upon either the URL requested, any HTTP header in the request or even the source IP of the client making the request. By leveraging the power of regular expressions, patterns can be as complex as needed to get the job done.
These are just a few samples of what you can do. As of version 6.0-32, LoadMaster fully supports PCRE style regular expressions for content rules and header modifications. This allows for a tremendous amount of control over your rules, giving administrators the flexibility they need for just about any application.
Let’s give Content Switching a shot. We’ll be creating a rule to direct requests for an intranet server to a specific server.
We will be directing requests for “internal.example.com” to the first server and all other requests to the second server. First we select the first server and add the “Internal” rule. Then go back and select the second server. This time we will add the “default” rule. The default rule is a catchall for everything that doesn’t match any rule. If no default rule is applied, non-matches will be rejected by the service.
Once both rules are applied, we’re done configuring the service. LoadMaster will now direct traffic based on the header specified by the client.
Now let’s turn our attention to Header Modification. Header Modification is another way LoadMaster takes advantage of regular expressions to make changes to traffic on the fly. This can accomplish some very neat effects and can reduce the amount of changes necessary on the real server to support load balancing. Header modifications can be used to insert, remove or modify HTTP headers either in requests or responses or to modify URLs before they are passed to real servers.
Some examples from the field are:
From the examples listed, it’s plain to see that these could also be configured on real servers themselves. However by configuring these on LoadMaster you can avoid server changes. This can save time and effort and simplify your setup by consolidating these types of changes on LoadMaster where they can be easily managed and backed up.
When configuring LoadMaster to replace text in a header or URL, it may be useful to perform backreferencing in the regular expressions so part or all of the original value is included in the replacement value. This is good for prepending or appending text to an existing string.
Select the button on that page for Create New … to begin creating the rule. We’ll then give the rule a name. For this example, I used ‘Redirect_Root.’ I then selected ‘Modify URL’ as the Rule Type.
For the Match String I specified “^/$” — this is a regular expression that essentially states match “/” and only “/”, this corresponds to the request which is sent when no specific URL is specified. For the Modified URL I set “/owa”, but this could be any URL you’d like.
Let’s take a look at one application of header modification to get a better idea of how this works. We’ll be working with the example of redirecting the root of a web server to a specific directory using a ‘Modify URL’ rule. To create the rule, navigate to Rules & Checking > Content Rules. Once the rule is created, navigate to the HTTP or HTTPS service you want to apply the rule to.
Send any ideas you’d like to share to [email protected] or post them on our forums.
Andrew Conti, Support Team Lead - North America, Kemp Technologies