[root@server]# cat /usr/local/nginx/conf/upstream.conf
upstream vserver_01 {
server 172.21.198.136:8001 weight=1 max_fails=1 fail_timeout=30;
}
upstream vserver_02 {
server 172.21.198.136:8002 weight=1 max_fails=1 fail_timeout=30;
}
#基于cookie
#map $http_cookie $vserver {
# ~*VT2$ vserver_02;
# ~*VT1$ vserver_01;
# default vserver_01;
#}
#基于header
map $http_x_custom_header $vserver {
~*VT2$ vserver_02;
~*VT1$ vserver_01;
default vserver_01;
}
测试:
curl --header 'X-Custom-Header: VT1' -v http:///test.html
curl --header 'X-Custom-Header: VT2' -v http:///test.html