In the earlier days of Linux web server hosting, the only popular option was Apache. These days however, the market share is pretty even divided between Apache, NGINX, and then other alternatives, at least on Linux and Unix based systems. Both packages allow relatively easy setup of a web service to allow serving HTTP and HTTPS content. Both are also completely viable options for most situations, though one or the other may be a better choice depending on circumstances. This article aims to highlight the similarities and differences between these two options in order to allow you to make an informed choice on the best option for your needs.
A Case for Apache
Apache is the A in the popular LAMP stack (Linux, Apache, MySQL, PHP) that is still one of the most popular frameworks for serving a website in use today. This is partially due to Apache itself, which is an extremely flexible web server platform. Compared to NGINX, Apache has a larger feature set that can be enabled through the installation of various add-on modules. Official and non-official modules exist for both Apache and NGINX, but Apache has more available.
Additionally, Apache has supported dynamic loading of these modules, and has for some time now. This means that all modern modules for Apache are compatible with dynamic loading as well. NGINX by comparison has only recently added dynamic module support in 2016. This means not all modules are compatible with dynamic loading yet, but progress has been made toward this end.
Apache has also been around in some form or another for almost 3 decades now. This means there is a huge amount of resources available to learn from and thus be able to optimize your Apache environment. Additionally, the official documentation for Apache is some of the best available on the internet.
A Case for NGINX
NGINX was originally designed to meet a challenge of being able to handle at least 10,000 concurrent connections at once from a single server. This is still feasible with NGINX and an appropriately spec’d server. As a result it is built in such a way as to be exceptionally efficient at handling static content requests. This design can also allow NGINX to handle fluctuation in the load amount a bit more gracefully.
The design of NGINX also makes it exceptionally efficient at processing static content requests. In benchmarks comparing Apache’s performance, NGINX averages around twice as fast to serve static content. The two are also mostly comparable on dynamic content delivery speeds.
NGINX also has support for a few more items than Apache. These include media streaming options and reverse-proxy for non-HTTP protocols. NGINX also has the ability to act as a front-end for another web server. This would allow one, as an example, to combine the static content performance of NGINX with the module flexibility of Apache.
Which is best for me?
Apache and NGINX are actually quite comparable, with only a few key differences as outlined above that set them apart. Thus, choosing the best option is not a function of choosing the best web server software, but a function of what you wish to accomplish, and which software fits that best. If you find your site or application serving mostly static content, it may be a good idea to consider NGINX for the performance gains. If you require custom modules Apache may be the better choice. If you have both, you can always live with one or the other, or even combine the two.
Regardless of choice, both web servers have extremely good official documentation and loads of third party advice, guides, and information. Both have support for various additional features such as load-balancing, modular add-ons, and wide OS compatibility. Both are also viable choices for most situations.