Created
December 13, 2014 08:20
-
-
Save fordnox/a915dceecb63707844cf to your computer and use it in GitHub Desktop.
Split clients nginx conf
This file contains hidden or 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 1; | |
error_log /var/log/nginx/error.log; | |
pid /run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
split_clients "${remote_addr}-{$query_string}" $goto { | |
50.0% "http://127.0.0.1:8081"; | |
* "http://127.0.0.1:8082"; | |
} | |
server { | |
listen 8080; | |
return 301 $goto; | |
} | |
server { | |
listen 8081; | |
return 200 "server1\n"; | |
} | |
server { | |
listen 8082; | |
return 200 "server2\n"; | |
} | |
} |
Thanks for your post.. but I am trying to send 50% traffic to another host but it does not work.. see this config
split_clients "${remote_addr}" $goto {
50.0% "http://serverA.domain.com";
50.0% "http://serverB.domain.com";
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name serverA.domain.com;
root /usr/share/nginx/html;
return 200 $goto;
location / {
proxy_set_header Host $host;
proxy_pass http://$goto;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test: