Apache vs. NGINX: Which Web Server Is Better?
In this blog, our expert compares Apache vs. NGINX to help teams decide which web server is a better fit for their needs. The Apache HTTP Server (often referred to as just “Apache”) and NGINX are often at the top of the list for enterprises considering open source web servers. However, there are some important differences between them that teams should understand before deciding which one to implement.
Keep reading to learn about the different features and use cases for Apache vs. NGINX, two popular web infrastructure technologies.
- What Is the Apache HTTP Server?
- What Is NGINX?
- Apache vs. NGINX: Key Differences
- When to Use Apache vs. NGINX
- Final Thoughts
What Is the Apache HTTP Server?
The Apache HTTP Server is a free open source web server created by a group of software developers that formed the Apache Group.
It started as an offshoot of the NCSA httpd server in 1995, and has expanded since then. The Apache Software Foundation was formed in 1999 to support the Apache HTTP Server.
What Is NGINX?
NGINX is a free open source HTTP and reverse proxy server, along with a generic TCP/UDP proxy server. NGINX Plus is the commercial offering, which is available through paid subscription and includes additional features.
NGINX was created in 2004, and a company was created in 2011 to provide support and the NGINX Plus paid software, which was then acquired by F5 in 2019.
Apache vs. NGINX: Key Differences
Apache and NGINX both have distinct strengths and limitations. In this section, we’ll look at how their features differ across several key areas.
Apache is currently built with a modular architecture. The core has the direct interaction with the client, but modules are used to add extra features from the base. Nearly everything else is a module, even SSL/TLS. There are many modules for different features, such as URL rewriting and load balancing. Apache has several different worker models — the most popular are prefork, worker, and event, and each has its own advantages and disadvantages.
NGINX uses an event-driven architecture which is similar to Apache, but with one worker per cpu. NGINX is able to upgrade the binary without downtime using the same method as reloading a new config. It does this by starting a new main process to handle new connections, with old workers ending when their connections are completed until all old processes have exited.
Static and Dynamic Content
Both Apache and NGINX can serve static files directly from the file system. NGINX tends to perform faster because of the way it caches files.
They also can both serve dynamic content, but by different methods. Apache can provide dynamic content by integrating a language processor in a module, and providing it directly. NGINX, however, needs to pass requests to an external process that provides content, which Apache can do as well.
Both Apache and NGINX have text configuration files that are similar in nature, but not identical. They both can include files in order to separate common configuration options or features. They both support virtual servers and configurations for separate locations or paths.
However, Apache allows directory-level configuration using .htaccess files, while NGINX doesn't. This makes NGINX a little more efficient since it doesn't need to search for .htaccess files and interpret them, and a bit more secure by not allowing additional configuration. However, this makes Apache a bit more appropriate for shared environments since users of individual sites can apply their own configurations.
They both support reloading the configuration without restarting and dropping connections, but they do it in different ways. NGINX also supports updating the binary without losing connections.
In both Apache and NGINX, the main process listens for connections and passes them to worker processes after accepting one. Then the workers process the request based on their model — event-driven for NGINX, and either event, worker, or prefork for Apache.
Apache uses dynamically loadable modules to add additional functionality or features. It comes with more than 50 official modules, and third-party modules are available. Being dynamic, they can be built and loaded at any time.
NGINX has more than 100 third-party modules, but they are not dynamically loaded, so they need to be compiled within the core software itself. Dynamically loaded modules are available with the commercial offering, NGINX Plus.
Apache provides support through the documentation, a users list, and an IRC chat channel. Support can also be purchased through third-party providers.
F5 (the current owners of NGINX) provides support for their commercial offering, NGINX Plus. There is also documentation, an IRC channel, and other resources.
When to Use Apache vs. NGINX
Both Apache and NGINX can be used to meet a multitude of application requirements. However, there are a few considerations for enterprise deployment that teams should keep in mind.
Apache Use Cases
Apache is better for shared hosting environments, due to its ability for non-privileged users adding configuration files for individual directories.
NGINX Use Cases
NGINX generally has better performance for static files, so it is typically used for a front-end or a proxy to back-end services. This makes is ideal for load balancing requests, and it is often used as an ingress controller in Kubernetes. However, it can't serve dynamic content by default, and needs to proxy all dynamic content requests to a back-end server.
Using Apache and NGINX Together
It is common to use NGINX as a reverse proxy in front of Apache. NGINX would typically be used to serve static content, passing any other requests back to Apache to server dynamic content.
When it comes to comparing Apache vs. NGINX, one is not necessarily better than the other. Depending on your environment and application needs, it may make more sense to use Apache or NGINX, or use them together as described above.
In the 2023 State of Open Source Report, survey participants listed both Apache HTTP and NGINX among the most business-critical open source software for their organizations. When asked specifically about which web infrastructure technologies they are using, 18.23% selected Apache HTTP and 11.47% selected NGINX.
In other words, usage of the two appears to be fairly comparable, with Apache ahead by about 7%. This makes sense given that the Apache Server has been around longer, and is backed by the very established Apache Software Foundation. NGINX adoption is growing, but whether it will ever surpass Apache remains to be seen.
Looking For NGINX or Apache HTTP Support?
OpenLogic can help you configure your web server properly and provide SLA-backed technical support for your entire open source infrastructure. Available 24/7/365, our Enterprise Architects have 15+ years of experience with open source enterprise deployments.
- Blog - Tomcat vs. NGINX
- Blog - Top 5 Takeaways From the 2023 State of Open Source Report
- Course - NGINX Training
- Guide - Open Source in the Enterprise