Apache vs NGINX — what are the biggest advantages?

Diana Salacka
DreamCommerce
Published in
3 min readDec 1, 2016

The two most popular open source HTTP web servers in the world have been fighting over a clear share on the market. They both can provide a complete web stack, but NGINX is said to support dynamic content better — tempting for VPS and dedicated hosting users, and Apache speed and performance stays a benefit for shared hosting clients. Let’s have a look at the most common advantages and disadvantages of the two rivals.

How do they work?

The main difference between the web servers is connected with how they operate and handle traffic and connections. Apache is the most popular server since 1995 and thanks to that it has a large documentation and supports not only the common LAMP (Linux, Apache, MySQL, PHP) stack, but also other stack components like Node.js. It’s a light architecture designed to provide configure different multi-processing modules (MPM), that determine the requests. These are: prefork model — single thread process, that works with one connection at a time, worker model — manages multiple threads, creating child processes, that handle a single connection each, and a event model — that not only creates listener thread that passes connections to a worker thread but handles keep-alive connections, that basically handlerequest as the connection runs.

NGINX was an answer to “how to get one web server to handle 10,000 connections, given the limitations of the operating systems?” problem, commonly known as the C10K problem. It can be easily scaled on minimal hardware, focuses on core web server and proxy features. Most importantly, it does not manage threads the same way Apache does. It does not set up a new process for each web request — it combines worker processes, and each of them handles multiple connections. The mechanism loops the requests, checking and processing events and works on a connection only when an event is triggered. Nginx is an asynchronous, non-blocking, event-driven connection handling algorithm, that is designed to serve static content quickly and to handle dynamic requests off to other software.

Static Content

Apache uses MPM methods to handle static content, and NGINX because of different methods of handling threads has a much greater performance. It is about 2.5 faster than Apache — tested on 1k concurrent connections. With 512 concurrent connections NGINX showed to be two times faster.

Dynamic Content

Apache process dynamic content by it’s MPM work models. It sets a processor into it’s worker instances, which allows to execute dynamic content in the web server, not having to use third-party components. NGINX does not handle the dynamic content internally — all dynamic requests are passed to external processor for execution. It communicates with the processor through protocols like http, FastCGI, SCGI, uWSGI, memcache, and waits for the rendered content response. This means, that static content responds quicker on NGINX as the dynamic content is not embedded in the server’s native work process, but when it comes to dynamic performance measurements, Apache and NGINX go head to head. They both handle the same concurrency in PHP runtime environment and almost the same performance in other languages.

Operating system

Both Apache and NGINX run on Unix-like systems, but only Apache has a full support Microsoft Windows support. That does not mean that NGINX can’t handle Microsoft, just Apache performs a bit better in this matter.

Configuration

Directory-level configuration in Apache allows to interpret directives within the content directories themselves — the files interpreted by Apache are called .htaccess files. They are kept in the content directories and Apache checks the components for .htaccess files to apply the directives within them. Those files are not supported by NGINX and the server does not provide outside configuration. However, there are some positives about that situation — when system directory-level .htaccess files are called out, Apache checks for those files in every parent directory, reads and interprets them for each request. Meanwhile, NGINX handles request faster, as it does a single directory lookup.

We, at DreamCommerce use NGINX to manage multi-ecommerce platforms.

--

--

Diana Salacka
DreamCommerce

A philosopher by passion and marketing specialist by a hobby… Or the other way around? Picking up the pace with DreamCommerce in IT updates, apps and news.