Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
basic nginx conf for continuous experimentation
upstream _a {
upstream _b {
upstream _c {
# Chain of upstream conditions
# ----------------------------
# In order of preference, set upstream by:
# - url parameter
# - cookie
# - random
split_clients $date_gmt $random_splitter {
10% _a;
10% _b;
80% _c;
map $cookie__v $cookie_upstream {
'_a' _a;
'_b' _b;
'_c' _c;
default $random_splitter;
map $arg__v $upstream {
'_a' _a;
'_b' _b;
'_c' _c;
default $cookie_upstream;
# EOF of upstream conditions
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://$upstream$request_uri;
proxy_pass_request_headers on;
proxy_set_header Host $host;
add_header X-Time $date_gmt;
proxy_set_header X-Time $date_gmt;
# Cookbook: splitter
# Recipe: splitter::nginx
# Author: Dave Nolan <>
# Description: Configure nginx to act as an a/b splitting load balancer
include_recipe 'nginx::default'
include_recipe 'nginx::ohai_plugin'
# FIXME: include_recipe 'nginx::http_stub_status_module'
include_recipe 'splitter::default'
configuration ='variants', node[:project]))
template "splitter" do
path "#{node['nginx']['dir']}/conf.d/splitter.conf"
source "nginx.conf.erb"
owner "root"
group "root"
mode "0644"
"configuration" => configuration,
"server_name" => node[:splitter][:server_name],
"split_strategy" => node[:splitter][:strategy]
notifies :reload, resources(:service => "nginx")

tobijb commented Sep 5, 2013

Hey there TextGoesHere,

How did this end up working out for you? I'm doing something similar. I like the date_gmt touch!


tobijb commented Sep 5, 2013

On a strange side note, looks like you work/worked for Lonely Planet which my current company, shares a building with in Oakland, CA. Anyhoo...


textgoeshere commented Oct 23, 2013

Hey, works out great. Essentially the same code powers A/B tests here today.

Hah, small world! I'm actually based in London, UK. We're now also building a tech team in Franklin, TN if you're interested...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment