Created
October 4, 2012 13:49
-
-
Save textgoeshere/3833637 to your computer and use it in GitHub Desktop.
basic nginx conf for continuous experimentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
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/