Martin Martin - 1 year ago 116
Apache Configuration Question

Nginx v Apache for high traffic sites


be a more suitable choice as a web server for high traffic websites?

The site we will be building is an e-commerce site, if that makes a difference.

I am really interested in the actual 'why' from a technical point of view either way. i.e., why would
be a better choice for this type of site from a technical standpoint, or the opposite, why it wouldn't?

Answer Source


In general, Nginx is better for high-traffic sites due to its event-driven architecture. Rather than handling each request in a distinct thread, it uses non-blocking I/O to service many requests in each thread.

The important aspect of this architecture is the reduced use of processes or threads. A thread can consume anywhere from 2MB to over 64MB of RAM. So when Apache serves a 10KB JPEG, it may actually be using a significant amount of RAM. It becomes worse if you have slow clients (e.g. smartphones) where the request may keep a thread busy for several seconds.

Many people find that running Nginx as a proxy in front of Apache to be an ideal middle ground. Nginx talks to the slow clients and can do so using a very small amount of RAM. When requests are forwarded to Apache, the request speed is limited by your local connectivity, not that of the remote user. This means that the network bottleneck will not keep the request (and it's memory-hogging thread) alive for any longer than necessary.

In short you get the low-resource benefits of Nginx coupled with the wide feature-set of Apache.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download