Nginx Split Test A/B

Have you ever wanted to split test multiple pages on your website? You could use a WordPress plugin called Simple Page Tester but you are limited to testing two urls at a time. After some searching, I came across a simple way to split test multiple URLs using Nginx split client module.

First, add this section to the top of your Nginx Config:

split_clients "${remote_addr}AAA" $destination {
 20% https://example.com/page-1/;
 30% https://example.com/page-2/;
 40% https://example.com/page-3/;
 10% https://example.com/page-4/;
}

Next, add a rewrite rule to your server section:

server {
 rewrite ^/rewrite-url-goes-here/$ $destination redirect;
}

Finally, restart Nginx to see the changes:

sudo service nginx restart

Hope this is helpful. It can also be used to redirect Nginx to random URLs. Let me know if you have any questions below.

Leave a Reply

Your email address will not be published. Required fields are marked *