Apache and Nginx

NGINX vs Apache: Head to Head Comparison

Posted in Apache, Nginx
NGINX vs Apache: Head to Head Comparison

The two most popular open-source web servers(Source) powering the Internet today are the Apache HTTP server and NGINX. Over 50% of the websites in the world run on these two web servers. For almost two decades, Apache Web server served around 60 percent of the world’s websites until its competitor NGINX (pronounced as “engine-x”) came into existence. Due to the explosive growth in data traffic volumes and the number of users of the world-wide-web, NGINX was introduced to overcome the performance limitations of Apache web servers. NGINX, designed for higher concurrency, can be deployed as a standalone web server, and as a frontend proxy for Apache and other web servers.

What is Apache?

Apache was developed to deliver web content which is accessed through the internet. It is notable for playing a key role in the initial growth of the World Wide Web. Apache is an open-source software developed and maintained by an open community of developers and it runs on a wide variety of operating systems. The architecture includes the Apache Core and modules. The core component provides the basic server like capability, so it accepts connections and manages concurrency. The various modules correspond to different functionalities that are executed on each request. A specific Apache deployment can be configured to include different modules such as security features, management of dynamic content or for basic HTTP request processing.

“One-server-does-all” model was the key to the early success of Apache. However, as traffic levels increased and web pages became richer and performance was a constraint, tuning Apache to cope with real-world traffic became complex.

What is NGINX?

NGINX was written specifically to address the performance limitations of Apache web servers. The performance and scalability of NGINX arise from its event-driven architecture. It differs significantly from Apache’s process-or-thread-per-connection approach. In NGINX, each worker process can handle thousands of HTTP connections simultaneously. Hence NGINX is an implementation that is lightweight, scalable, and has high performance. This architecture makes the handling of high and fluctuating data loads much more predictable in terms of RAM usage, CPU usage, and latency.

NGINX also has a rich set of features and can perform various server roles:

  • A reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols
  • A load balancer and HTTP cache
  • A frontend proxy for Apache and other web servers, combining the flexibility of Apache with the good static content performance of NGINX

Difference between Apache and Nginx

1. Simplicity

Developing and innovating applications on Apache is easy. The one-connection-per-process model makes it very easy to insert modules at any point in its web serving logic. Developers could add code in such a way that if there were failures only the worker process running the code would be affected. Processing of all other connections would continue undisturbed.

NGINX, on the other hand, has a sophisticated architecture hence developing modules is not easy. NGINX module developers need to be very careful to create efficient and accurate code, without any failures, and to interact appropriately with the complex event-driven kernel to avoid blocking operations.

2. Performance

Performance is measured by how the server delivers large volumes of content to the client browser and this is an important factor. Content can be Static or Dynamic.

Let us see some statistics on this.

2.1. Static Content

NGINX performs 2.5 times faster than Apache according to a benchmark test performed by running up to 1,000 simultaneous connections. Another benchmark running with 512 simultaneous connections, showed that NGINX is about twice as fast and consumed less memory. Undoubtedly, NGINX has an advantage over Apache with static content. So if you need to serve concurrent static content, NGINX is a preferred choice.

2.3. Dynamic Content

For displaying dynamic content, Speedemy’s benchmark test results revealed that the Nginx vs apache performance for both were exactly the same. A probable reason for this is, almost all of the request processing time is spent in the PHP runtime environment rather than the core part of the webserver. The PHP runtime environment is pretty similar to both web servers.

Apache can also process dynamic content by embedding a processor of a language like PHP into each of its worker instances. This allows it to execute dynamic content within the web server itself without having to rely on external components. These dynamic processors can be enabled through the use of dynamically loadable modules.

NGINX does not have any ability to process dynamic content natively. To handle PHP and other requests for dynamic content, NGINX must pass to an external processor for execution and wait for the rendered content to be sent back. However, this method has some advantages as well. Since the dynamic interpreter is not embedded in the worker process, its overhead will only be present for dynamic content.

3. OS support

Apache runs on all operating systems such as UNIX, Linux or BSD and has full support for Microsoft Windows. NGINX also runs on several modern Unix-like systems and has support for Windows, but its performance on Windows is not as stable as that on UNIX platforms.

4. Security

Both Apache and NGINX are secure web servers. The Apache Security Team exists to provide help and advice to Apache projects on security issues and to coordinate handling security vulnerabilities. It is important to configure the servers properly and know what each option in the settings does. There are many guidelines to secure the servers to prevent security attacks.

5. Flexibility

Web servers can be customized by adding modules. Apache has had dynamic module loading for the longest time, so all Apache modules support this.

NGINX Plus(NGINX Plus is a software load balancer, web server, and content cache built on top of open source NGINX) uses a modular architecture too. New features and functionality can be added with software modules, which can be plugged into a running NGINX Plus instance on demand. Dynamic modules add functionality to NGINX Plus such as geo-locating users by IP address, resizing images, and embedding Lua scripts into the NGINX Plus event-processing model. Modules are created both by NGINX, Inc., and third-party developers.

The majority of the necessary core module functionality (e.g., proxy, caching, load-balancing) is supported by both web servers.

6. Support and Documentation

A major point to consider is the available help and support for the web servers among other software. Because Apache has been popular for so long, support for the server is fairly ubiquitous. There is a large library of first and third-party documentation available for the core server and for task-based scenarios involving hooking Apache up with other software.

Along with documentation, many tools and web projects include tools to bootstrap themselves within an Apache environment. This may be included in the projects themselves, or in the packages maintained by your distribution's packaging team.

Apache, in general, has more support from third-party projects simply because of its market share and the length of time it has been available.

For NGINX, in the past, it was difficult to find comprehensive English-language documentation due to the fact that most of the early development and documentation were in Russian. However, today the documentation has been filled out and there are now plenty of administration resources on the NGINX site and available documentation by third parties.

Nginx vs Apache: Head to Head Comparison

To summarize, here is a tabular view of the feature sets between Nginx vs Apache:

Feature Apache NGINX
Simplicity Easy to develop and innovate because of its one-connection-per-process model Complex to develop as it has a sophisticated architecture to handle multiple connections concurrently.
Performance – Static Content Slow in displaying static content 2.5 times faster than Apache and consumes less memory
Performance –Dynamic Content Excellent Performance for dynamic content Excellent Performance for dynamic content
Operating system support Supports all OS – Unix like and Windows Supports all OS – Unix like and windows however performance on Windows is comparatively less stable.
Security Is a secure web server. Understanding and configuring the security features are important Is a secure web server. Understanding and configuring the security features are important
Flexibility It can be customized by adding modules. Apache had dynamic module loading for the longest time. NGINX version 1.11.5 and NGINX Plus Release R11 introduced compatibility for dynamic modules.
Support and Documentation Excellent support and documentation are available as it has been in the market for a very long time. Though there was a weak start for support and documentation for NGINX, it has grown rapidly hence now it has excellent resource support and documentation available.

NGINX and Apache – Working together

For many applications, NGINX and Apache complement each other well. A very common starting pattern is to deploy the open-source NGINX software as a proxy (or NGINX Plus as the application delivery platform) in front of an Apache-based web application. NGINX performs the HTTP-related heavy lifting – serving static files, caching content, and offloading slow HTTP connections – so that the Apache server can run the application code in a safe and secure environment.

Conclusion

As seen, both Apache and NGINX are powerful, flexible, and capable. The latest versions of both the servers are competitive in all areas. Deciding which server is best for you is largely a function of evaluating your specific requirements and decide the best option.

People are also reading:

Sindhuja Hari

Sindhuja Hari

Sindhuja Hari, a technology geek, content producer & writer brings over 20 years of experience. She builds and delivers best in class content for global audiences. Her favorite domains/ genres are IT, Manufacturing, Logistics & Supply Chain, and Travel & Leisure. View all posts by the Author

Leave a comment

Your email will not be published
Cancel
Rochelle Mathis
Rochelle Mathis

Do you need nginx with node?

Tina White
Tina White

Whenever you develop a website using Node then you need some port on the server to run that node. By default, it runs on a typical webserver port that is 80. That’s how you can access your node server and you do not need Nginx to run this.

Anita Pittman
Anita Pittman

How does Apache handle multiple requests?

Brendan Keller
Brendan Keller

To handle many requests the Apache server has to create different threads of execution for each request made to the server. A thread is a part of a program that is run to complete a specific task. Each thread will handle the request made to the server along with their response to the client. This is how Apache manages multiple requests.

Marc Zimmerman
Marc Zimmerman

How much traffic can Apache handle?

Betsy Gonzales
Betsy Gonzales

By default, Apache is configured to handle 150 concurrent connections to the server. The request above this has to wait for the earlier requests to complete.

Marion Richards
Marion Richards

Why Apache Cannot handle 10K connections?

Antonia Rogers
Antonia Rogers

Apache is a thread based web server and its connections are distributed into different threads. Each thread can run only one request at a time. If we run 10k connections it may overload the server and the request will be run too slow and increase the traffic for other requests.

Jimmy Barker
Jimmy Barker

How do I use Apache and Nginx together?

Shannon Klein
Shannon Klein

You can follow the below steps to make them work together.
First, select the different IP address for each one and set up the host page to a quick start and append lines for the local IP address.
After that setup listens to IP and port for Nginx and Apache.
Restart both servers to work.

Johnathan Hill
Johnathan Hill

Is Nginx Russian?

Delia Schwartz
Delia Schwartz

Nginx was basically developed by a Russian developer in 2004. This webserver becomes famous very fast due to its features and faster than Apache. For a long time, it was used to manage the heavy loaded Russian sites and served dynamic HTTP content on the network.

Emanuel Soto
Emanuel Soto

Can Apache run with nginx?

Stanley Vaughn
Stanley Vaughn

Yes, you can use both the servers at the same time. But you need to change the default config as both of them try to listen on the same port and the same IP. You can run either one behind the other or side by side.

Jeremiah Armstrong
Jeremiah Armstrong

How much RAM does Nginx need?

Jeanette Henry
Jeanette Henry

Nginx is highly optimized and does not require much disk and memory. Ngnix’s master process requires around 16MB and each worker requires at least 100-300 MB and later it depends on your project configuration. If you do not have a big load then 128 MB will be sufficient. If you want to cache some extra data for quick access you may need extra disc space.

Shawna Nichols
Shawna Nichols

How does nginx reverse proxy work?

Earl Conner
Earl Conner

A reverse proxy is a service that takes client request and sends them to one or more proxied servers. Then it fetches response and sends the server’s response to the client. Nginx is highly scalable and secure, thus Nginx is widely used as a reverse proxy for HTTP and non-HTTP servers.

Mandy Frazier
Mandy Frazier

Is nginx secure?

Jerome Smith
Jerome Smith

Well, Nginx is relatively secure than another web server. It has a better and quick turnaround whenever a bud is found which sets a benchmark for security. Just like mod_security in Apache, Nginx has another advanced rule set that works like mod security.