

Using nginx as a load balancer - mickeyben
http://mickeyben.com/2009/12/30/using-nginx-as-a-load-balancer.html
Nothing new, all is in the documentation. I just tried to make the things simpler for noobs as I was few hours ago on this subject.
======
justinsb
Everyone knowledgable about nginx (that I've talked to) says not to use it as
a load balancer though. Best practice seems to be to front haproxy with nginx.

I've personally encountered some pretty serious issues when a back-end server
isn't responding (nginx hanging); the _balancing_ aspect is non-existent,
though there's a third party nginx module for it (upstream_fair); but it
generally doesn't seem like there's motivation to encourage/support using
nginx as a load balancer.

It's a pity, because nginx does SSL much better than haproxy does. We're still
using nginx but we monitor it _very_ closely.

~~~
jbyers
We use nginx 0.7.x as a load balancer and have no complaints. A pair balance
25M+ requests a day.

It's certainly not a full-featured load balancer -- nothing like the
visibility and control you get with haproxy or similar -- but for us it's
never been a problem. Our backends handle up to 100 concurrent requests and we
use straight round-robin across a large pool. In ~2 years, nginx has never
hung, mis-balanced requests, or skipped a beat. One node failed once because
of human error during a binary upgrade, and I was pissed -- I thought I could
keep the thing running forever.

Many of the horror stories I used to see on the nginx lists were in cases
where each backend could only handle one request at a time, which I think was
the genesis of upstream_fair. I suspect this is a big reason for the bad load
balancing reputation.

What's missing is easily taking servers out of rotation and non-trivial health
checks. Both can be done with config file changes, and nginx's graceful
restart mechanism is very robust. But there's no side-channel for changing
upstreams on the fly.

nginx + haproxy is a fine choice if you need more control, and I've seen
haproxy on both sides. Haven't used SSL support in haproxy, but it's good in
nginx.

~~~
whyleyc
Out of interest how beefy are the servers you are using to run nginx ? We're
looking at it for a deployment and I'm wondering if you had any tips about
whether it's a particularly RAM or CPU-hungry beast ?

~~~
jbyers
We have single-processor 4GB AMD 1216 and 1354s running nginx. Neither one
goes above 20% CPU while doing a few hundred req/s. If we were doing a lot
more SSL the picture might change, but nginx seems very efficient.

~~~
whyleyc
Thanks - very helpful to know. One follow-on question - you mention you use 2
machines, is this in a failover capacity or do you use another piece of
hardware/software to balance in front if nginx ?

------
noss
While on the topic of nginx, is anyone using nginx to split the groups for
performing a/b testing? It seems like a sensible place to randomly place
visitors in groups with cookies.

------
theli0nheart
Just use HAProxy.

