Skip to content

Instantly share code, notes, and snippets.

@textgoeshere
Created August 20, 2012 08:22
Show Gist options
  • Save textgoeshere/3402203 to your computer and use it in GitHub Desktop.
Save textgoeshere/3402203 to your computer and use it in GitHub Desktop.
port = lambda do |env|
body = "Hello from variant #{ENV['VARIANT']} on #{env['SERVER_NAME']}:#{env['SERVER_PORT']} at #{env['HTTP_X_TIME']}"
[200, {"Content-Type" => "text/html"}, [body]]
end
run port
worker_processes 1;
events {
worker_connections 1024;
}
http {
access_log /home/dave/scrap/nginx-split/access.log;
error_log /home/dave/scrap/nginx-split/error.log;
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;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment