Advantages of Using Nginx or HA Proxy as Load Balancer
In our environment we us both Nginx and HA Proxy on different clusters. Are there advantages of using one over the other?
Or, what is the best way to go about load balancing a basic LAMP server cluster?
(I'm not going into the "best way to load balance", since that's obviously situation specific.)
Both HAProxy and nginx are excellent choices for open-source HTTP load balancers on Unix. At a very high level, the pros and cons that come first to mind are IMHO:
nginx:
- Can do SSL offloading (often a biggie).
- Has a rich set of content processing modules, i.e. header rewriting, content compression, etc.
- Can sometimes be 'the only HTTPd you need', making administration simpler if you don't need any other HTTPd's.
- More extensible with plugins, f.x. for routing traffic.
HAProxy:
- Can offer higher single-server performance than nginx (especially when running in TCP mode, 10gbit/s has been demonstrated).
- IMHO simpler to get up and running for basic plain HTTP load balancing setups.
- Changes a bit less, especially the slightly older stable branches often go for a while without needing security & stability updates.
But as said, both are excellent choices. Pick the one you feel most comfortable with.
That really depends on what you want to do.
Nginx can split load between clusters, as well as route specific domains to different clusters. Our nginx performance has been satisfactory. It's more like a load router.
For haproxy I know it queries the server status constantly, and will check the server before directing traffic to it. It also has an interface where you can view statistics. nginx I don't think does this on either score.
We use nginx as a webserver, and are very happy with it. I'm never going back to Apache. The downside is if you're intent on running PHP; it requires some hackery-jiggery to make it work under fastCGI.
Don't forget to put Varnish in place for caching! That simple step solves a lot of the problems of sites being Slashdotted/Fireballed!