Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An A/B testing work-in-progress
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
# weighted routing
split_clients "${date_gmt}${arg_random}" $split_site {
50% "old";
* "new";
}
map $cookie_DYN_USER_ID $selector_dynuserid {
default "dynuserid"; # This will only match non-empty values because of the match below
"" ""; # This is technically the default because it matches an empty value
}
map $cookie_site_upstream $selector_cookie {
"old" "cookie";
"new" "cookie";
}
map $arg_site $selector_arg {
"old" "arg";
"new" "arg";
}
map "$selector_dynuserid$selector_cookie$selector_arg" $use_selector {
default "split";
"arg" "arg";
"cookie" "cookie";
"dynuserid" "dynuserid";
}
map $use_selector $site_upstream {
"arg" $arg_site;
"cookie" $cookie_site_upstream;
"dynuserid" "old";
"split" $split_site;
}
map $use_selector $site_upstream_cookie {
default "$site_upstream; Path=/; Max-Age=604800"; # 60seconds * 60minutes * 24hours * 7days = 604800
"dynuserid" "deleted; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
map $site_upstream $site_host {
default "503"; # This should never happen
"old" "www.example-a.com";
"new" "www.example-b.com";
}
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
include /etc/nginx/debug_headers.d/*.conf;
add_header Set-Cookie "site_upstream=$site_upstream_cookie";
#include /etc/nginx/debug_here.conf;
include /etc/nginx/proxy_settings.conf;
proxy_pass https://$site_host;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.