Nginx vs. Apache: When and Which Web Server is the Right Choice

Nginx vs Apache

When it comes to choosing a web server, Apache and Nginx are the two most famous representatives. Here we present the two and show when and which one is the better choice.

Nginx and Apache are both open-source web servers – apart from that, some differences speak for the one and sometimes for the other system.

Apache: Flexible and long-lasting

The Apache HTTP Server was introduced in 1995 and is the most widely used web server. A big plus for Apache is the wide distribution and that it has long been on the market. Many systems, such as CMS, work with Apache. Modules such as PHP or mod_rewrite can be flexibly reloaded.

One disadvantage of Apache is the performance. This is not a big problem with smaller sites, but if the number of concurrent requests increases, the server’s resource hunger also increases. This is because Apache starts a separate process for each open connection to the web server, which requires memory. Hundreds or thousands of concurrent queries are just as many processes. When the Apache web server project was started, this was not problematic since at the time large load peaks were rather rare.

Nginx: Performance and light weight

Nginx was introduced first in 2002 and developed directly with performance mind. The focus of the project is on the core web server and the proxy functions. Nginx handles connections differently than Apache and relies on an asynchronous architecture – one process is not started per connection, but thousands of connections can be handled per process. The consumption of resources remains relatively constant even with load peaks, which is why even with limited hardware, high-performance sites with a lot of accesses can be delivered. Nginx can also be extended by modules, which however have to be compiled into the system. A dynamic loading as in Apache is not possible.

In contrast to Apache, Nginx only supports the delivery of static content – requests for dynamic content are passed on to other software. Also, no configuration adjustments at directory level are supported by .htaccess files. Overall, the setup of a Nginx server is usually more complicated than that of an Apache server, but this is only important if you really want to deal with server administration. For providers of Nginx hosting, modules for common tasks should be available.

Apache and Nginx

Instead of using Apache or Nginx only, the following scenario is also possible: You switch a Nginx server to one or more Apache servers. The Nginx takes care of all static queries and redirects the dynamic to Apache so that the Apache server receives significantly fewer requests. This way, you can set the Apache modules for dynamic tasks and do not need to install any external helpers for the Nginx.

Conclusion

To answer the question, when and which web server is more useful: Theoretically, Nginx should always be a better choice because of the performance advantages. Practically it looks different: If you do not know server administration, you have to go back to a web hosting provider, and often rely on Apache. But there are also providers that offer Nginx – some of which we have presented in an article.

Here, however, you may have to deal with adjustments that must be made before a software runs on Nginx (for popular systems there will be instructions). So if you only want to install software on a web server without any adjustments, Apache is often the better choice.