1
我想将nginx设置为负载均衡器。但我想设置它的方式是某些请求(具有特定参数)只会发送到某些主机。基本上想法是在原始请求中使用任何主机,然后如果用户指定某个参数,例如bla0,然后将请求重定向到主机0,而对于BLA1主办1.因此,这里是我的配置想出了:nginx负载均衡器/位置难题
# load balancing server
server {
listen 8000;
server_name example.com www.example.com;
# requests to bla0 server
location ~ ^(/request).*bla0$ {
proxy_pass http://localhost:8081;
}
# requests to bla1 server
location ~ ^(/request).*bla1$ {
proxy_pass http://localhost:8082;
}
# for default location use balancer
location/{
proxy_pass http://cluster;
}
}
upstream cluster {
server localhost:8081;
server localhost:8082;
}
但不幸的是这种配置不起作用。我总是得到轮询请求,即/请求?q = bla0进入任一主机。我错过了什么。
伟大的提示,这是我一直在寻找。所以位置规则变成这样:location/{proxy_pass http:// cluster; if($ args〜pattern1){proxy_pass http:// host1} if($ args〜pattern2){proxy_pass http:// host2}} – Valentin