Does it make sense to put Nginx in front of HAProxy?
-
We have a scaling cloud-based setup that is running 1 application server most of the time, scaling up to 2 or 3 servers during peak hours. For load balancing, we use HAProxy on a separate machine. Now on the load balancing machine we would like to serve static content directly, and cache some of the dynamic content, to take some of the load off of the application servers. Nginx can do both of these tasks, but it can also do load balancing. I read however that Nginx is not as fast as HAProxy when it comes to load balancing, so would it make sense to pass requests from Nginx to HAProxy to do the actual load balancing, or would requests still suffer from added delay due to cache lookups in Nginx? In other words, is replacing HAProxy with Nginx a good idea, or would you recommend combining the two?
-
Answer:
One use-case is to use nginx to terminate SSL, then forward to haproxy which then loadbalances to your regular pool of web services -- the same can be done with stunnel + haproxy as well...
Matt Billenstein at Quora Visit the source
Other answers
It makes all sense to do static and dynamic serving independently. Some people combine static serving and load balancing in the same software and/or part of the architecture. But, that does not mean it has to be always in the same place. Perhaps putting nginx before HAProxy may be the best option in your case. There are other options as to put all your static content in other domain name, and that way splinting completely static and dynamic serving. Using this later aproach, would be easier in the future to add load balancing to the static serving cluster or for example use a CDN.
Leo Lara
Short Answer NO. Long Answer:- 1. The HAProxy as LB should be left on its own standalone machine no matter what the motivation. It is a super-terrible idea to share this machine for some other purpose. 2. If you compare the scale that Nginx can handle compared to HAProxy, it should be rapidly clear that HAProxy can do connection processing for a lot more number of connections than Ngnix. Just from a Bandwidth matching perspective nothing should be put in front of an HAProxy ( definitely not a stateful firewall ). Nginx can't replace HAProxy and it shouldn't be put in front of it to reduce number of connections to it. 3. It makes all the sense in the world to service static and dynamic content from different end points as mentioned by Leo in one of the answers. 4. HAProxy can terminate SSL these days so that use case is not out. Just noticed that this is a 4 year old question. Anyway bump it up :-)
Tarun Dua
If I were charged with solving this problem, I would run Varnish on the host that runs HAProxy, and route requests for static assets from HAProxy to Varnish, which is configured to send cache missses to the backend Nginx application servers. Varnish could also cache the dynamic content, as well.
Dossy Shiobara
The cost that nginx has to pay to do load balancing is a cost that you're already paying if you're doing caching. I suspect that nginx with multiple upstreams will be faster than nginx in front of haproxy. But the only way to know for sure is to try both and monitor throughput.
Bob Poekert
I have another approach : I always put an HAproxy in front of a Nginx. If I arrive to more than one server, I put another HAProxy in front of Nginx, the other nginx is a backup of the first. (I load balanced between haproxy using round robin DNS) Why: in 3 years of use of HAProxy, I never see HAProxy falling down, but Nginx sometimes (not a lot). On the last installation I made for a huge facebook apps, I put ten dedicated server with this configuration. So if one dedicated server is down, only 10% of the traffic is lost (Where all the traffic will be lost if we have only one load balancer). This ten dedicated servers are "little" dedicated servers, but all cumulated, we serve arround 500Mb/s only in web traffic.
Boris Pigeot
May be need to look on something like Apache Traffic Server for building you own CDN service with pair of haproxy+nginx?
Sergey Yaroslavtsev
Related Q & A:
- Does it ever make sense to use RAM Disk to force RAM allocation for tempdb with SQL Server 2008?Best solution by Database Administrators
- How to make nginx to redirect multiple subdomains?Best solution by stackoverflow.com
- How do you make a collage of pictures to put on Myspace?Best solution by Yahoo! Answers
- Can anyone put the following paragraphs into different words still making sense?Best solution by Yahoo! Answers
- How to make videos to put into YOUTUBE?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.