Skip to content

Instantly share code, notes, and snippets.

@merltron-pa
merltron-pa / nginx.conf
Last active October 31, 2019 11:05
NGINX Traffic Splits Article: nginx-config-snippet1.conf
upstream upstream_cms_old {
server 123.23.123.123:443;
}
upstream upstream_sap {
server 44.44.44.44:443;
}
@merltron-pa
merltron-pa / nginx.conf
Last active October 31, 2019 11:07
NGINX Traffic Splits Article: nginx-config-snippet2.conf
split_clients "${remote_addr}${http_user_agent}" $split_upstream {
99% upstream_cms_old;
* upstream_sap;
}
@merltron-pa
merltron-pa / nginx.conf
Last active October 31, 2019 11:08
NGINX Traffic Splits Article: nginx-config-snippet3.conf
map $cookie_migration_split $chosen_upstream {
default $split_upstream;
"upstream_cms_old" "upstream_cms_old";
"upstream_sap" "upstream_sap";
}
@merltron-pa
merltron-pa / nginx.conf
Last active October 31, 2019 11:08
NGINX Traffic Splits Article: nginx-config-snippet4.conf
if ($deliver_upstream = 'upstream_sap') {
# users should stay on the new site forever
set $cookie_lifetime '31536000'; # 60*60*24*365 = 1 year
}
@merltron-pa
merltron-pa / nginx.conf
Last active October 31, 2019 11:09
NGINX Traffic Splits Article: nginx-config-snippet5.conf
# overwrite the upstream by appending "?force_upstream=oldcms" to the URL
map $arg_force_upstream $deliver_upstream {
default $chosen_upstream;
"oldcms" "upstream_cms_old";
"sap" "upstream_sap";
}
@merltron-pa
merltron-pa / nginx.conf
Last active October 31, 2019 11:09
NGINX Traffic Splits Article: nginx-config-snippet6.conf
add_header Set-Cookie "migration_split=$deliver_upstream;Path=/;Max-Age=$cookie_lifetime;";
proxy_pass https://$deliver_upstream;
}
@merltron-pa
merltron-pa / nginx.conf
Last active October 31, 2019 11:10
NGINX Traffic Splits Article: nginx-config-snippet7.conf
map $remote_addr $bypass_ip {
default 0;
"1.111.111.111" 1;
}
map $remote_addr $bypass_ip_to_sap {
default 0;
"22.22.22.22" 1;
"33.33.33.33" 1;
"44.44.44.44" 1;
@merltron-pa
merltron-pa / nginx.conf
Last active October 31, 2019 11:11
NGINX Traffic Splits Article: nginx-config-snippet8.conf
map $http_user_agent $bypass_user_agent {
default 0;
~*(Googlebot|bingbot|Slurp) 1;
}
System.out.printf("How long is %s? Well, it's %d %n characters long of course!", "a piece of string", "a piece of string".length());
/* OUTPUT: How long is a piece of string? Well, it's 17 characters long of course! */
print("How long is %s? Well, it's %s characters long of course!" % ("a piece of string", len("a piece of string")))
# OUTPUT: How long is a piece of string? Well, it's 17 characters long of course!