haproxy as load-balancer and nginx as webserver?

6,998

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.

Share:
6,998

Related videos on Youtube

feketegy
Author by

feketegy

Updated on September 18, 2022

Comments

  • feketegy
    feketegy over 1 year

    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:

    1. haproxy is better load-balancer than nginx
    2. nginx is better web server than apache

    So my question is that which setup is better?

    1. Using haproxy as load-balancer and nginx as web server?
    2. Using nginx as both load-balancer and web server?
    3. 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?

    • the-wabbit
      the-wabbit over 12 years
      There is no definition for "better" in your context. The evaluation of software is a quite complex procedure and requires knowledge of so many details of your personal (planned) setup that nobody is going to be able to give you a comprehensive advice. This is the reason why questions of such kind are regularly closed on serverfault.
    • feketegy
      feketegy over 12 years
      Ok, I edited my post. I'm interested in high performance, high availability server setup. where the web app. will process huge loads of XML files which then needs to be written in MySQL
    • the-wabbit
      the-wabbit over 12 years
      I need a car. It has to be fast and reliable. People are going to get in and out of it quite often and occasionally bring some baggage. Given all that, is it better to have the car fueled by gasoline or diesel?
    • feketegy
      feketegy over 12 years
      Instead of such comments why wouldn't you tell me which setup do you prefer? Or how's your servers setup?
  • feketegy
    feketegy over 12 years
    I'm thinking of putting haproxy in front of nginx and use PHP-fpm + MySQL for reading on each node, then create a dedicated instance for just MySQL for writing.
  • RichVel
    RichVel over 11 years
    good answer - since you can just put static files onto a CDN for high volume sites, the overhead of Apache vs Django/Rails/PHP apps is not that great, as you say.
  • Ronald Poon
    Ronald Poon over 10 years
    Hello @zerodeux. It's rare to find someone give an intelligent answer to the Apache vs Nginx debate. Thanks.