This article describes how to configure easy A/B testing in Nginx.
Background Prerequisites
Sometimes we need to do simple A/B tests that don’t require complex conditions, so we can use Nginx’s ngx_http_split_clients_module module.
Install the ngx_http_split_clients_module module
Generally this module already comes with it, if not it is recommended to install our packaged N.WTF
Configuring Nginx
For example, we want 20% of our users to be forwarded to the URL https://example.com/, 30% to the URL https://example.org/, and the rest to the URL https://examle.edu/.
In the above example, the IP address plus the AAA string requested by the visitor is converted to a number using MurmurHash2, and if the resulting number is in the first 20%, then the $ variant value is https://example.com/, and the corresponding value in the middle 30% interval is https://example.org/, and the rest is https://example.edu/.
Then we find two machines with different IPs and test them.
Machine A.
Machine B.
Then there can be more flexible uses, such as specifying different directories.
|
|
Specify a different home page.
|
|
This relatively simple A/B test is now complete ~