What is the Difference Between NGINX and Apache?

Posted on by Ronald Caldwell | Updated:
Reading Time: 4 minutes

When comparing NGINX vs Apache Web Server, developers should consider the advantages and disadvantages of both offerings. The needs of your website or applications will determine which of the two pieces of webserver software to choose.

This guide answers what is the difference between NGINX and Apache.

Apache

Apache is the most commonly used web server software on the Internet, and for a good reason. Its long history and general reliability, thorough documentation, and active support community have helped it grow. But Apache’s universal support has not come without some trade-offs, especially using apache vs NGINX with WordPress.

How Apache Works

Apache excels at serving web pages, though its memory requirements increase with more workload, thanks to how Apache manages processes. Apache’s Multi-Processing Module (MPM) governs its process management. The most common modules are Prefork, Worker, and Event.

Each time a new request comes in, Apache creates a new process to handle it. Here is how each module handles this:

  • In prefork mode, each process contains a single thread (the code that runs inside a process).
  • In worker mode, each process can contain multiple threads, each handling a single connection.
  • In event mode, each process can contain multiple threads, but each can handle more than one connection at a time.

The Worker module creates fewer new processes than the Prefork module, and Event creates fewer than Worker. Regardless of the MPM used, Apache creates new processes to handle new incoming requests.

Advantages of Apache

Cost

Apache is free and open source software, which means that there is no cost to use it. This is an attractive feature and the main reason why users that use the LAMP stack don’t deviate from the default software.

Flexibility

There is an extensive list of modules that can be added to Apache. The ability to customize the software to your needs is invaluable when setting up your web server.

Cross-Platform Usability

Apache is also a cross-platform software that is compatible with Windows, BSD, and Linux operating systems.

Disadvantages of Apache

Resource Intensive

The way Apache handles requests makes it resource-intensive. As requests keep coming in and new processes are created to handle them, CPU and memory usage continue to increase. This increase in needed resources creates more load, slows the server down, and if requests exceed the server’s capabilities, could cause it to become unresponsive.

Increased Cost

As a result of the potential need of increased resources, Apache can be cost-prohibitive. With Apache, scaling your environment typically requires adding RAM or CPU cores to cope with significantly increased traffic.

NGINX

NGINX is open source web server software used as a drop-in replacement for Apache and focuses on high performance, scalability, high availability. It seeks to improve upon the performance of Apache by capitalizing on its weaknesses. NGINX manages multiple requests simultaneously with minimum hardware resources, providing low RAM usage with high compatibility.

How NGINX Works

Unlike Apache, NGINX does not create new processes to handle incoming requests. Instead, it runs with a set number of processes, typically one per CPU core, and each uses a single thread to handle many requests (potentially thousands) simultaneously. NGINX also caches as it serves, making future requests that much faster still.

Because of this, NGINX’s resource requirements don’t tend to increase with incoming requests like Apache’s. And thanks to its relatively small footprint and caching capabilities, NGINX is able to do the job considerably faster.

Advantages of NGINX

Cost

Probably the only place of equality between the two pieces of software is the cost. Like Apache, NGINX is free and open source. It is usually not included in most tech stacks, so it requires installation before use.

Easily Configured

NGINX does not have as complicated a configuration process as Apache. Low configuration times allow your environment to get up and running in less time.

Lightweight and Scalable

The way NGINX handles processes allows it to be less resource-intensive and able to handle much more traffic. It provides more performance for your money, allowing your infrastructure to go much longer without needing to upgrade.

Disadvantages of NGINX

Performance Gains are Only for Static Content

It is important to note that the potential performance gains with NGINX are most dramatic when serving static content. Unlike Apache’s all-in-one approach, NGINX can serve only static content natively (such as HTML, images, javascript, and css). To keep it as lightweight as possible, NGINX relies on separate applications like PHP FastCGI Process Manager (FPM), Tomcat, or Apache to serve dynamic content.

Limited Operating System Support

NGINX is available for Unix-based operating systems with limited to no support for Windows. Users with Windows-based servers would need to use an alternative web server software.

NGINX vs Apache Considerations

When considering NGINX vs Apache, some might choose one over the other while others may choose to use both. Your needs will determine which option works best for you. 

Apache’s resource usage is not defined by the type of content it’s serving. Processes are created and threads are spun off based only on the number of incoming requests. That makes it somewhat less than ideal for serving extremely large amounts of small, static resources.

By allowing NGINX to serve the static content and pass requests for dynamic content to Apache, you can effectively eliminate the drain on resources that otherwise would have been caused by having Apache serve all that static content.

Additional Considerations for NGINX vs Apache

  • Once installed, Apache needs to be configured to run on another port.
  • After switching the Apache port, sites on the server would not be accessible at their normal URLs until NGINX is installed, properly configured, and running.
  • NGINX handles virtual hosts (vhosts) differently than Apache, and each existing virtual host entry would need to be recreated for NGINX.
  • Some control panel software, such as cPanel/WHM, does not officially support NGINX (although WHM/cPanel plugins are available).

Wrapping Up

What is the difference between NGINX and Apache? The way that they handle processes differs, but they still have their pros and cons depending on your needs. Apache vs NGINX will come down to how you want your webserver to perform, whether or not you use WordPress, or what your websites and applications demand.

Liquid Web’s VPS Hosting, Cloud Dedicated Servers, and Dedicated Servers are what your infrastructure needs. Contact our sales team today to get started.

Avatar for Ronald Caldwell

About the Author: Ronald Caldwell

Ron is a Technical Writer at Liquid Web working with the Marketing team. He has 9+ years of experience in Technology. He obtained an Associate of Science in Computer Science from Prairie State College in 2015. He is happily married to his high school sweetheart and lives in Michigan with her and their children.

Latest Articles

How to Create a MySQL Database in cPanel

Read Article

How to Create a MySQL Database in cPanel

Read Article

What is the Difference Between NGINX and Apache?

Read Article

Accessing Man Pages on Ubuntu 16.04 LTS

Read Article

What is VMware Fusion?

Read Article