Content-Switching

Different from load-balancing virtual servers, content-switching virtual servers don’t point to real servers, instead, they select a load-balancing virtual server. This would allow, selecting different servers for mobile devices, different data base servers for writing to the data base and reading from the database (this is widely used in large-scale webshops), and many more.

My example does not maks sense, however, it’s easy to use and to understand: My content-switching vServer will return different colors, depending on which browser you use.

It’s based on the User-Agent strings of browsers:

  • Microsoft Internet Explorer:
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko
  • Microsoft Edge:
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36 Edg/96.0.1054.53
  • Mozilla Firefox:
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0
  • curl
    User-Agent: curl/7.55.1

I highlighted the respective significant string.

Citrix AC/NetScaler Content Switching vServers

Go to Traffic Management → Load Balancing. Create three load-balancing vServers:

  • lb_vs_red, Type HTTP, non-addressable
  • lb_vs_blue, Type HTTP, non-addressable
  • lb_vs_green, Type HTTP, non-addressable

Citrix ADC/NetScaler: Non Adressable vServer

Navigate to Traffic Management → Content Switching.

Check, if it is marked with an exclamation mark within the yellow circle. This means: Feature not enabled. Right-click Content Switching and enable the feature, so the exclamation mark within the yellow circle disappears. Alternatively, you could go to System → Settings → Configure Basic Features and enable Load Balancing.


The content-switching policies

The actions

Even though it’s not absolutely needed, it is strongly advised, to create contetnt.switching actions. The action simply contains the vServer.

Navigate to Traffic Management → Content Switching → Actions. Click Add.

Citrix ADC/NetScaler content-switching action

Click on the arrow next to “Target Load Balancing Virtual Server” and select the server. There are three actions to create:

  • cs_act_red, target load-balancing vServer lb_vs_red
  • cs_act_blue, target load-balancing vServer lb_vs_blue
  • cs_act_green, target load-balancing vServer lb_vs_green

The Policies

We create three policies. One for the old and outdated Microsoft Internet Explorer. The website should appear in red. One for Chromium-based Browsers (Google Chrome, Microsoft Edge, and many more). The website should appear in blue. And one for Mozilla Firefox. The website should be green.

Citrix ADC/NetScaler content-switching policy

Click the arrow next to action and select the action previously created. Click The wizard next to “expression” and type the expression.

The appropriate policy expressions are:

  • cs_pol_red: HTTP.REQ.HEADER("User-Agent").CONTAINS("Trident")
  • cs_pol_blue: HTTP.REQ.HEADER("User-Agent").CONTAINS("Chrome")
  • cs_pol_green HTTP.REQ.HEADER("User-Agent").CONTAINS("Firefox")

The content-switching vServer

Like any vServer exposed to users, a content-switching vServer has a protocol, an IP address, and a port.

Navigate to Traffic Management → Content Switching → Policies. Click Add.

Configuration data:

  • Protocol: HTTP
  • IP: 192.168.229.120
  • Port: 80

Citrix ADC/NetScaler content-switching vServer

Testing:

Surf to 192.168.229.120. You should see a “HTTP/1.1 Service Unavailable” message. You see, the vServer is up and working, however, it got no policies bound, so it does not know what to send, and therefore answers with an http status 503.


Binding Policies

Binding Priorities:

  • cs_pol_red, 100
  • cs_pol_blue, 110
  • cs_pol_green, 120

Open up your content-switching vServer. Click to No Content Switching Policy Bound.

 

Citrix ADC/NetScaler: Binding content-switching PoliciesSelect cs_pol_red.

Set the priority to 100 and click Bind. Repeat for blue and green.

Citrix ADC/NetScaler: Binding content-switching Policies

Testing:

Surf to this website, using Microsoft Internet Explorer, a Chromium-based browser, and Firefox.

Next, try to use curl; curl is a tool, built into Windows (and all UNIX/Linux OS), made to download a webpage. Curl sends a user-agent string, but it does not contain any of the keywords we used before.

You see, we get a 503, service unavailable. This happens, if none of the policies matches.

Let’s unbind the green Policy and bind the green server as a “Default Virtual Server”. Still, for all browsers, the result will stay the same, however, curl now returns a 200 OK:





Leave a Comment

Your email address will not be published.