Last active
November 15, 2021 11:05
-
-
Save kmjones1979/f3e147a6d792593395d9b42977fd5fcb to your computer and use it in GitHub Desktop.
This is an example NGINX configuration for the blog: Performing A/B Testing with NGINX - This demonstrates split_clients based routing on an argument named token
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
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 version_1a { | |
server 127.0.0.1:3001; | |
} | |
upstream version_1b { | |
server 127.0.0.1:4001; | |
} | |
split_clients "${arg_token}" $dynamic { | |
95% version_1a; | |
* version_1b; | |
} | |
server { | |
listen 3001; | |
location / { | |
return 200 "Token: $arg_token\t\tServed from site $dynamic. \n"; | |
} | |
} | |
server { | |
listen 4001; | |
location / { | |
return 200 "Token: $arg_token\t\tServed from site $dynamic!! \n"; | |
} | |
} | |
server { | |
listen 80; | |
location / { | |
proxy_set_header Host $host; | |
proxy_pass http://$dynamic; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment