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 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
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 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
tobijb
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...
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... |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
textgoeshere
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... http://www.lonelyplanet.com/jobs/
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/ |
Hey there TextGoesHere,
How did this end up working out for you? I'm doing something similar. I like the date_gmt touch!
-JB