Compare Nginx and Apache (& Learn How to Choose)

Disclosure: HostScore is reader-supported. When you purchase through our links, we may earn a commission.

Both Nginx and Apache are mature products with rich feature sets and high performance. They share common open-source origins, and you can deploy them either on Windows or Linux servers. 

However, some key differences might make you choose one over the other.

For example, Apache is a comprehensive solution that supports many different technologies and modules out-of-the-box. In contrast, Nginx relies on third-party modules to expand its functionality.

To see which web server might better suit your needs, let’s dive deeper into these options.

Nginx vs Apache – Notable Differences

FeaturesNginxApache
Introduced20041995
Current Stable VersionNginx 1.21.6Apache 2.4.53
ArchitectureEvent-drivenProcess-driven
Open SourceYesYes
Development & SupportApache FoundationF5 Networks
Supported PlatformsPrimarily UnixUnix and Windows
Multiple Concurrent RequestsYesNo
Native Dynamic Content ProcessingNoYes
ModularYesYes
ConfigurationLimitedper-directory via .htaccess
Request InterpretationPasses URIPasses File system location

Features Comparison: Nginx vs Apache

Architecture

Nginx and Apache share some similarities in their core architecture. For example, they both use master-worker processes to improve performance. They even have similar configuration files. Yet the differences in architectural style result in significant broad-view performance variation.

Nginx has a resource-friendly event-driven architecture that uses small but constant amounts of memory under load. This characteristic makes it ideal for hosting websites with high traffic levels or those that have intermittent traffic spikes.

Apache’s process-driven architecture handles each connection via a dedicated thread, which requires more memory. However, it scales better under heavy loads on machines with more CPU cores and RAM.

Memory Usage

Nginx is known for its high performance and low resource consumption. On the other hand, Apache can be memory intensive, especially when running multiple server blocks. While both use memory to handle HTTP requests, Nginx is more lightweight. 

The design of Apache meant that it spawned one thread per connection, and each thread would use a certain amount of RAM. As traffic increased, this could lead to problems as more RAM would be required, particularly on servers with less memory. Apache also creates new processes for each request, even from the same user.

Comparatively, Nginx uses one process to handle multiple connections at once. 

PHP Handling

Because both of these web servers mainly work with PHP, how they handle the code means significant performance potential. Nginx does not execute PHP directly by default. Instead, it passes the request to PHP-FPM (FastCGI Process Manager), which handles the request and sends a response back to Nginx, which then serves the content back to the client.

Since Nginx does not wait for a response from PHP-FPM to serve another request (similarly to how it does not wait for a response from clients when serving static content), Nginx can handle more requests concurrently than Apache will be able to manage.

Apache uses a module called mod_php to execute PHP code. In this model, every time an HTTP request comes in, Apache spawns a new process or thread (depending on how it’s configured) to handle that request. This process is also responsible for handling any PHP requests within that request.

This model works, but it has some drawbacks. For one thing, spawning a new process for every request can be intensive on the system, especially if there are many simultaneous requests. Generating a new process for every PHP request within a request is even more intensive since the operating system has to spawn a brand new interpreter for each one.

About Apache

Apache

The Original Hero Web Server

Created in 1995 by Robert McCool and originally called the “Apache HTTP Server Project” (hence the name), Apache was designed to create a robust, commercial-grade server that is free to use, even with modifications. It became popular very quickly because it could run on many different operating systems, from Unix to Windows.

Because of this long-running popularity, I consider Apache as the “original hero” web server. It’s robust, well documented, and supported by an open community of developers under the auspices of the Apache Software Foundation.

About Nginx

Nginx

Titan of a New Era

Nginx (pronounced as “Engine X”) is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server used to host websites and applications of all sizes. It was first publicly released by Russian developer Igor Sysoev. Nginx’s initial goal was to solve the C10K problem that Apache struggled to manage. 

Note: In 2019, Nginx became part of F5 Networks. F5 is a technology company specializing in application security, multi-cloud management, and online fraud prevention.

How to Choose Between Nginx & Apache

As you can see, there’s no clear winner between these web server behemoths. It mainly depends on what you need the webserver to manage. 

Choose Apache if: 

  • You are running a medium/large scale website that is likely to grow significantly over time and requires custom modules.
  • You have many virtual hosts or modules enabled in your server and need them all on startup.
  • You’re running a small website and don’t want to spend the time learning how to configure Nginx properly.

Use Nginx if:

  • You are running a large-scale website and want to easily configure caching & load balancing at the same time without worrying about hardware limitations.

Final Thoughts on Nginx vs Apache

Whether you run Apache or Nginx will depend on your needs and the hardware you’re running. You can use either option for serving PHP websites. But there is a lot more to consider than just that. 

If you have a simple website, you may not notice any difference between them. But if your site gets more traffic and grows, you’ll need to know how each server performs and scales under load.


More from HostScore

Hosting Cost Calculator

Are you overpaying for your web host?

Tell us about your website and we'll help estimate how much you need to pay for your web host for the next 12 months.

Try Now (Free Tool)

Popular Hosting Search

HostScore readers are also searching for...

Article by Timothy Shim

Timothy Shim is a writer, editor, and tech geek. Starting his career in the field of Information Technology, he rapidly found his way into print and has since worked with International, regional and domestic media titles including ComputerWorld, PC.com, Business Today, and The Asian Banker. His expertise lies in the field of technology from both consumer as well as enterprise points of view.
Photo of author