Skip to content

Instantly share code, notes, and snippets.

@ltk
Created August 5, 2014 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ltk/dae1949ec6465a1880bd to your computer and use it in GitHub Desktop.
Save ltk/dae1949ec6465a1880bd to your computer and use it in GitHub Desktop.
Split Test Load Balancer Nginx Configuration
map $split_test_cookie_name $split_test_cookie {
default $cookie_split_test_version;
}
upstream app.com {
server old.app.com;
}
split_clients "app${remote_addr}${http_user_agent}${date_gmt}" $upstream_variant {
10% "test";
* "original";
}
map $split_test_cookie $upstream_group {
default $upstream_variant;
"test" "test";
"original" "original";
}
geo $internal_request {
ranges;
4.3.2.1-4.3.2.254 1;
default 0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name app.com www.app.com;
set $split_test_cookie_name "split_test_version";
location = / {
add_header Set-Cookie "${split_test_cookie_name}=$upstream_group;Path=/;Max-Age=518400;";
set $test_group 0;
if ($upstream_group = "test") {
set $test_group 1;
}
if ($internal_request = 1) {
set $test_group 0;
}
if ($test_group = 1) {
return 302 http://new.app.com/;
break;
}
proxy_pass http://app.com;
}
location / {
proxy_pass http://app.com;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment