Nginx – using Nginx as reverse proxy to apache or stand alone

apache-2.2nginxPHPPROXYreverse-proxy

I've read a lot about this issue (including all threads in this site) and couldn't come to a conclusive decision.

What is considered better (performance and security wise) for very high load sites (millions of users per day):

  1. standalone Nginx + PHP + SQL
  2. Nginx as a revers proxy for Apache + PHP + SQL

What I don't get is – if Nginx can run dynamic content why use Apache at all?

Best Answer

I have 20+ web servers running nginx+php-fpm behind a pair of HAProxy balancers. In my opinion, and from my own experience, this is the optimal setup. Not taking anything away from Apache (I use it for over 10 years), but Nginx simply blows its socks off.

HAProxy is the best open source load balancer. Period. I have tried many, including commercial offerings. I installed nginx on the load balancer as well to offload the SSL. It works like a charm, even under high load.

Splitting all the static content (images, css, js, etc) to separate nginx(s) gives you a further performance boost. HAProxy can send all static requests to a separate server, meaning you have the benefit of parallel requests in your back end systems.

If you do try HAProxy, remember to keep the MAXCONN setting for the web servers to a low (like 20 of 40) value. I see so many posts that have the web server maxconn setting being set to something like 1000 - which will result in HAProxy overloading a node in no time flat.

Related Topic