Skip to content

Instantly share code, notes, and snippets.

@textgoeshere
Created October 4, 2012 13:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save textgoeshere/3833637 to your computer and use it in GitHub Desktop.
Save textgoeshere/3833637 to your computer and use it in GitHub Desktop.
basic nginx conf for continuous experimentation
upstream _a {
server 127.0.0.1:8000;
}
upstream _b {
server 127.0.0.1:8001;
}
upstream _c {
server 127.0.0.1:8002;
}
# 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 <dave.nolan@lonelyplanet.com>
# 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 = Splitter::Configuration.new(data_bag_item('variants', node[:project]))
template "splitter" do
path "#{node['nginx']['dir']}/conf.d/splitter.conf"
source "nginx.conf.erb"
owner "root"
group "root"
mode "0644"
variables(
"configuration" => configuration,
"server_name" => node[:splitter][:server_name],
"split_strategy" => node[:splitter][:strategy]
)
notifies :reload, resources(:service => "nginx")
end
@tobijb
Copy link

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!

-JB

@tobijb
Copy link

tobijb commented Sep 5, 2013

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

@textgoeshere
Copy link
Author

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... http://www.lonelyplanet.com/jobs/

@bobf
Copy link

bobf commented Jul 8, 2020

Using date_gmt still useful 7 years later - cheers.

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