Chapter 3. Traffic Management
3.0 Introduction
NGINX and NGINX Plus are also classified as web-traffic controllers. You can use NGINX to intelligently route traffic and control flow based on many attributes. This chapter covers NGINX’s ability to split client requests based on percentages; utilize the 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.
3.1 A/B Testing
Problem
You need to split clients between two or more versions of a file or application to test acceptance or engagement.
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 addition of “AAA” to the first parameter is to demonstrate that this is a concatenated string that can include many variables, as mentioned in the generic hash load-balancing algorithm. 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 ...
Get NGINX Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.