-
-
Save morhekil/25b1804f6de91bf7a3bd765a21f98852 to your computer and use it in GitHub Desktop.
Split Test Load Balancer Nginx Configuration
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
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