Chapter 3. Traffic Management
Introduction
NGINX and NGINX Plus are also classified as web traffic controllers. You can use NGINX to intellengently route traffic and control flow based on many attributes. This chapter covers NGINX’s ability to split client requests based on percentages, utilize geographical location of the clients, and control the flow of traffic in the form of rate, connection, and bandwidth limiting. As you read through this chapter, keep in mind that you can mix and match these features to enable countless possibilities.
A/B Testing
Problem
You need to split clients between two or more versions of a file or application to test acceptance.
Solution
Use the split_clients module to direct a percentage of your clients to a different upstream pool:
split_clients "${remote_addr}AAA" $variant {
20.0% "backendv2";
* "backendv1";
}
The split_clients directive hashes the string provided by you as the first parameter and divides that hash by the percentages provided to map the value of a variable provided as the second parameter. The third parameter is an object containing key-value pairs where the key is the percentage weight and the value is the value to be assigned. The key can be either a percentage or an asterisk. The asterisk denotes the rest of the whole after all percentages are taken. The value of the $variant variable will be backendv2 for 20% of client IP addresses and backendv1 for the remaining 80%.
In this example, backendv1 and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access