haproxy as load-balancer and nginx as webserver? [closed]
EDIT: I'm interested in high availability, performance server setup.
I read a lot of articles about haproxy vs. nginx vs. apache etc. and this was my conclusion:
- haproxy is better load-balancer than nginx
- nginx is better web server than apache
So my question is that which setup is better?
- Using haproxy as load-balancer and nginx as web server?
- Using nginx as both load-balancer and web server?
- Using haproxy with apache?
My setup would be 2 separate servers with the following installed: load balancer, web server, PHP, MySQL for read
1 separate server for just MySQL write which then replicates to the 2 slave MySQL for read.
What do you think?
Solution 1:
Haproxy and Nginx are not the same beasts : haproxy only deals with the network and never touches the filesystem. It will never serve static content for you. On the other hand, it will perform an order of magnitude higher than any full fledged HTTP server like Nginx and Apache.
Haproxy is also a sophisticated load balancer, you need to have some use to it.
In my case, I'll use nginx or Apache up to 10,000 simultaneous connections on single servers or trivial setups because it does the job nicely and all by itself. For more involved architectures (many servers, high throughput), a dedicated loadbalancer like Haproxy is desirable.
Nginx vs. Apache is a moot point IMHO. I can scale both to 10,000 concurrent clients on a decent server (say 4 cores and 4G RAM), and if Nginx is a bit lighter on ressources, it does not make the difference since most of the time the app (Rails, Django, PHP, whatever) is 90% of the CPU+memory burden.
I'll say : use the web server you're the most comfortable with. OTOH it's true googling for Apache recipes is full of bullshit and it requires to carefully read the (large and very good) doc. As an Apache dinosaur, I'm very satisfied with it. But if you're new to HTTP web servers, I guess Nginx is less intimidating and more cool. Both Apache and Nginx are extremely reliable.
As for PHP, I use Apache with a worker MPM and FastCGI. Simple, efficient. I've documented that a long time ago on http://forge.bearstech.com/trac/wiki/DebianLamp : it's even easier on Debian 6.0 but I've not documented it.
Your setup seems fine to me (Haproxy + Apache or Nginx, then PHP via FastCGI). It's a good idea to put the loadbalancer on every front server instead on a distinct node (which becomes a SPOF). And it's simpler since every node runs the same setup. Add a an IP fail over and you're done.