Reputation: 599
I have posted this problem earlier: https://stackoverflow.com/questions/34977074/how-to-use-load-balancer-for-sockets
Basically my requirement is to send a particular url request to specific app server through load balancer.So i am looking for some kind of load balancer which can complete my requirement.
I was reading about nginx plus and found this link. https://www.nginx.com/resources/admin-guide/load-balancer/
There is one concept of sticky route in this documentation.I just want to know can it serve my purpose?
Upvotes: 2
Views: 1721
Reputation: 404
I believe what you need can be simply accomplished by HAProxy, which does a much more professional load balancing than NginX.
It has a feature where you can direct specific requests based on the URI
to specific backend server, using ACL
. Here is a very simple example (from default config file):
#---------------------------------------------------------------------
# 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
#---------------------------------------------------------------------
For more reading, check the official HAProxy Docs
Upvotes: 2
Reputation: 36
The sticky routes (aka sticky sessions or session persistence) is about keeping the client connected to the same upstream. This is helpful if you're load balancing logged in user sessions, payment transaction, etc.
I believe what you're looking for is location based routing. This would route requests such as /payment/* to one group of upstreams, and /login/* to another, etc. There's a section about this on the Microservices Solutions page.
What you'd want to do is define several upstream groups and then proxy_pass to these upstreams within different location blocks. I'll provide a brief example here:
upstream payments {
server backend1.example.com
server backend2.example.com
}
upstream login {
server backend3.example.com
server backend4.example.com
}
server {
...
location /payments {
proxy_pass http://payments;
}
location /login {
proxy_pass http://login;
}
}
(Disclaimer: I work at NGINX.)
Upvotes: 1