I had a scalability problem at work. Having about 3k customers with an average of 500 – 600 concurrent sessions and a middle aged all-in-one server, I have to balance http and https connections at least over 2 servers without changing the main IP address used by the client to start the application.
At the beginning, I evaluated Nginx, which is a well established http server (known for its outstanding capability on serving static resources) that has the capability to proxy requests to a pool of servers. I left this road quickly when I noticed that the proxy capability of Nginx does not supports (yet) sticky-sessions. In fact, when session affinity is required, Nginx can only route connection using source IP address as selection key, loosing the round-robin capability based on weight (that I need because I have server with different strength).
Looking for a balancer that supports weighted backend as long as affinity sessions, I foundHAProxy, which is considered the de-facto solution for this kind of problem. Again, evaluating this solution, I found something that bother me: HAProxy, in its stable version, can balance only http connection; it does not have support for https, which I need for my next version of the app.
HAProxy is really just a load balancer/reverse proxy. Nginx is a Webserver that can also function as a reverse proxy.
Here are some differences:
- Does TCP as well as HTTP proxying (SSL added from 1.5-dev12)
- More rate limiting options
- The author answers questions here on Server Fault 😉
- Supports SSL directly
- Is also a caching server
At Stack Overflow we mainly use HAProxy with nginx for SSL offloading so HAProxy is my recommendation.
“Nginx is becoming the standard for front end load balancing for many high traffic sites and this helps.”
I’ve used nginx as a load balancer, and it’s not pretty. All of the nginx load-balancing modules I’ve used, or seen used (I can think of at least five off the top of my head), have fallen apart under load, or not balanced intelligently, or just been plain bad. The modules I’ve used also tend to be hard to instrument, which makes working out exactly why they’re failing a bit of an adventure. I’m sure (I’d hope, at least) the load balancing modules in nginx have improved over time, but I’d still be very wary of it. In short: nginx is a kick-arse webserver, and I highly recommend it for that purpose, but as a load balancer I’d find something else.
My preference is for IPVS almost everywhere, as it runs at the IP layer and completely avoids all the ugly problems you just can’t avoid with a proxy. If you do feel the need to use a proxy, though, I would strongly recommend HAProxy over nginx. There are (narrow) circumstances in which a proxy is the best solution for the job, and I think HAProxy is the best of the bunch.
A example of how to configure HAProxy and Nginx