我之前已经发布过这个问题: https://stackoverflow.com/questions/34977074/how-to-use-load-balancer-for-sockets
基本上我的要求是通过负载均衡器向特定的应用服务器发送特定的url请求。所以我正在寻找某种可以完成我的要求的负载均衡器。
我正在阅读有关 nginx plus 的内容,并找到了此链接。 https://www.nginx.com/resources/admin-guide/load-balancer/
本文档中有一个粘性路由的概念。我只是想知道它能达到我的目的吗?
最佳答案
我相信您所需要的可以通过 HAProxy 轻松完成,它比 NginX 做了更专业的负载均衡。
它有一个功能,您可以使用 ACL
将基于 URI
的特定请求定向到特定后端服务器。这是一个非常简单的示例(来自默认配置文件):
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main *:5000
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
use_backend static if url_static
default_backend app
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:4331 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 127.0.0.1:5001 check
server app2 127.0.0.1:5002 check
server app3 127.0.0.1:5003 check
server app4 127.0.0.1:5004 check
#---------------------------------------------------------------------
如需更多阅读,请查看official HAProxy Docs
关于nginx - Nginx 加粘性路由方法是否适合基于路由的负载均衡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35161948/