Skip to content

Instantly share code, notes, and snippets.

@kmjones1979
Last active November 16, 2017 12:04
Show Gist options
  • Save kmjones1979/130b34cb5ee504c3428e9c802dccf43a to your computer and use it in GitHub Desktop.
Save kmjones1979/130b34cb5ee504c3428e9c802dccf43a to your computer and use it in GitHub Desktop.
Example NGINX configuration to perform A/B deployments
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events { worker_connections 1024; }
http {
default_type text/html;
log_format main '$remote_addr -> $request $status $body_bytes_sent bytes -> $upstream_addr';
access_log /var/log/nginx/access.log main;
upstream a {
zone a 64k;
server 127.0.0.1:3001;
}
upstream b {
zone b 64k;
server 127.0.0.1:4001;
}
split_clients "${arg_token}" $dynamic {
95% a;
* b;
}
server {
listen 3001;
location / {
return 200 "Served from site A! \n\n";
}
}
server {
listen 4001;
location / {
return 200 "Served from site B!! <<<<-------------------------- \n\n";
}
}
server {
status_zone website;
listen 80;
location / {
proxy_set_header Host $host;
proxy_pass http://$dynamic$uri$is_args$args;
}
location @healthcheck-a {
proxy_pass http://a;
proxy_connect_timeout 1s;
proxy_read_timeout 1s;
health_check uri=/ interval=1s match=health_check;
}
location @healthcheck-b {
proxy_pass http://b;
proxy_connect_timeout 1s;
proxy_read_timeout 1s;
health_check uri=/ interval=1s match=health_check;
}
}
match health_check {
status 200;
}
server {
listen 8080;
status_zone status-page;
root /usr/share/nginx/html;
location = /status.html { }
location = /status-old.html { }
location = / {
return 301 /status.html;
}
location /status {
status;
status_format json;
access_log off;
}
location /upstream_conf {
upstream_conf;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment