116 Apache and nginx Today and Beyond — How Modern Web Servers Work Together

The Technologies That Built the Web

For decades, Apache has been one of the foundational technologies behind the World Wide Web.

But today's web-server landscape is more complicated than it was during the early days of the LAMP stack.

Apache remains important, but another name appears frequently on modern servers:

nginx.

This can create an obvious question.

Is nginx replacing Apache, or do the two work together?

The interesting answer is: both are possible.

First, What Does Apache Actually Do?

Apache HTTP Server receives HTTP and HTTPS requests and determines how they should be handled.

If someone requests a simple file, Apache may send that file directly.

If the request requires PHP, Apache can pass the request into the PHP processing environment.

Apache can also perform redirects, authentication, access control, URL rewriting, compression, proxying, logging, and many other tasks.

In the classic LAMP architecture, Apache was often the primary doorway into the website:

Internet → Apache → PHP → MySQL

That model still works.

Then Came nginx

Nginx—usually pronounced “engine-x”—was created by Igor Sysoev and publicly released in 2004.

One of the problems it was designed to address was efficiently handling very large numbers of simultaneous network connections.

This was becoming increasingly important as websites grew.

Apache traditionally relied heavily on process- and thread-based approaches to handling connections. Nginx was designed around an asynchronous, event-driven architecture.

Rather than dedicating a separate process or thread to every connection, nginx could efficiently manage many connections with a relatively small number of worker processes.

That made nginx particularly attractive for high-concurrency workloads.

Apache and nginx Took Different Approaches

Apache and nginx developed with somewhat different philosophies.

Apache emphasized flexibility, modules, compatibility, and extensive per-directory configuration capabilities.

Nginx emphasized efficient connection handling, relatively low resource use, fast delivery of static content, proxying, and centralized configuration.

Neither philosophy is inherently better for every situation.

They solve overlapping problems in different ways.

Can nginx Replace Apache?

Yes.

A website can run using nginx without Apache.

A common arrangement is:

Internet → nginx → PHP-FPM → MySQL

In that architecture, nginx is the primary web server.

PHP-FPM provides the PHP processing environment, and PHP communicates with MySQL when database information is needed.

Apache is not required.

Can Apache Run Without nginx?

Absolutely.

Apache can remain the primary web server and handle incoming HTTP and HTTPS traffic itself.

A modern arrangement might look like:

Internet → Apache → PHP-FPM → MySQL

Again, nginx is not required.

This is why describing nginx simply as Apache's replacement can be misleading.

They are alternative web servers—but that is not the end of the story.

Can nginx and Apache Work Together?

Yes, and this is where modern server architecture becomes particularly interesting.

A system can place nginx in front of Apache:

Internet → nginx → Apache → PHP → MySQL

In this configuration, nginx receives the visitor's connection first.

It can handle certain requests itself and forward other requests to Apache.

When one server accepts a request and passes it to another server behind it, it can operate as a reverse proxy.

What Is a Reverse Proxy?

The term sounds more complicated than the idea.

Imagine a receptionist at the entrance to a large organization.

You do not walk directly into every department looking for the person you need.

You arrive at one entrance.

The receptionist determines where your request should go.

A reverse proxy performs a similar job for network requests.

The browser communicates with nginx.

Nginx can decide:

“I can handle this myself.”

or:

“Apache needs to handle this.”

The visitor does not need to know that multiple servers participated.

Why Put nginx in Front?

Nginx is very good at accepting and managing network connections.

It can efficiently deliver static resources such as images, stylesheets, JavaScript files, and downloadable files.

It can also handle HTTPS connections, compression, caching, proxying, and other front-end server tasks.

That means nginx can take some work away from Apache.

Instead of every request reaching Apache, nginx can deal with requests that do not require Apache's capabilities.

Let Each Layer Do What It Does Well

This gives us another useful way to think about modern server architecture:

nginx manages the front door.

Apache manages the website environment behind it.

PHP executes the application.

MySQL remembers the information.

That is not the only possible configuration, but it provides an excellent mental model for understanding why these technologies may appear together on the same server.

Static Versus Dynamic Content

The difference between static and dynamic requests helps explain why multiple layers can be useful.

Suppose a browser requests:

logo.jpg

That image already exists as a file.

No PHP program may need to run. No database query may be necessary.

The server simply needs to send the image efficiently.

Now suppose the browser requests:

post.php?pid=146

That request may require PHP to execute, retrieve a particular record from MySQL, construct HTML, and return the finished page.

Those two requests require very different amounts and types of work.

A layered architecture can route each request appropriately.

One Web Page Can Produce Many Requests

When we say that a browser requests “a web page,” we are simplifying what actually happens.

The browser may first request the HTML document.

After reading that HTML, it may discover that it also needs:

Loading one page can therefore produce many separate HTTP requests.

Efficiently handling all of those requests is one of the jobs of the modern web-server environment.

Where Does PHP-FPM Fit?

PHP itself has also changed how it commonly works with web servers.

Historically, PHP was often loaded directly into Apache through a module such as mod_php.

Modern servers frequently use PHP-FPM, which stands for PHP FastCGI Process Manager.

PHP-FPM runs PHP using managed pools of PHP worker processes.

The web server passes PHP requests to those workers.

Conceptually:

Request → Web Server → PHP-FPM → PHP Code

PHP-FPM can work with nginx, Apache, and other web-server arrangements.

This further separates responsibilities.

The web server handles web traffic.

PHP-FPM manages PHP execution.

Ports 80 and 443

Another part of the picture is the network port.

HTTP traditionally uses port 80.

HTTPS traditionally uses port 443.

A public-facing nginx server may listen for incoming traffic on ports 80 and 443.

If Apache is operating behind nginx, Apache can listen internally on another port.

The outside visitor never needs to know.

From the browser's perspective, it connected to the website normally.

Who Handles HTTPS?

In a layered system, HTTPS encryption can often be handled at the front-end server or proxy.

This is sometimes called TLS termination.

The browser establishes its secure connection with the public-facing server.

That server can then forward the request internally according to the system's architecture and security requirements.

This can centralize certificate handling and reduce duplicated work.

What About .htaccess?

This is one area where Apache and nginx differ significantly.

Apache can allow individual directories and websites to contain .htaccess files.

Those files can control redirects, URL rewriting, access rules, and other site-specific behavior.

Nginx does not use .htaccess files.

Its configuration is generally handled centrally through nginx configuration files.

That difference can be important when migrating an existing Apache website to nginx.

An Apache site that depends heavily on .htaccess rules cannot simply assume those rules will work under nginx.

Why Keep Apache Behind nginx?

If nginx can serve websites itself, why keep Apache at all?

Because existing websites may already depend on Apache behavior.

They may use .htaccess.

They may depend on Apache modules or configuration conventions.

Hosting management systems may be designed around Apache compatibility.

Administrators may have years of experience managing Apache environments.

Putting nginx in front can provide some of nginx's advantages while preserving the compatibility of the Apache environment behind it.

This Is Evolution, Not Necessarily Replacement

Technology history is often described as though one technology kills another.

The reality is usually more interesting.

New technologies sometimes replace older ones.

But they also supplement them, sit in front of them, communicate with them, or cause the older technology to evolve.

Apache did not disappear when nginx became popular.

Instead, server architectures gained another useful tool.

Apache Has Continued to Evolve

Apache itself has not remained frozen in the architecture of the 1990s.

Modern Apache supports different Multi-Processing Modules that determine how connections and requests are managed.

The event MPM, for example, improves Apache's ability to manage persistent connections efficiently.

Apache can also act as a reverse proxy itself.

It can communicate with PHP-FPM.

It can handle modern HTTP protocols and encrypted connections.

Today's Apache is the descendant of the original Apache HTTP Server, not a museum piece.

HTTP/2 and HTTP/3

The protocol used between browsers and servers has evolved as well.

HTTP/1.1 served the web for decades and remains important.

HTTP/2 introduced features allowing multiple requests to share a connection more efficiently.

HTTP/3 takes another major step by operating over QUIC, which uses UDP rather than the traditional TCP transport used by earlier HTTP versions.

The goal remains familiar:

Move information between client and server efficiently and reliably.

But the machinery underneath continues changing.

Then Came Content Delivery Networks

There can now be another layer even before nginx or Apache.

A Content Delivery Network, or CDN, can operate servers distributed across many geographic locations.

Frequently requested resources can be delivered from a location closer to the visitor.

A CDN may also provide caching, traffic filtering, protection against certain attacks, and other services.

A modern request could therefore look conceptually like:

Browser → CDN → nginx → Apache → PHP-FPM → MySQL

Not every request necessarily travels through every layer.

That is part of the point.

Each layer may determine whether it can satisfy the request without sending it farther down the chain.

Caching Means Sometimes PHP Never Runs

Caching provides another example.

Suppose PHP and MySQL previously generated a page that does not change very often.

A caching layer may save the result.

The next visitor requesting the same information might receive that saved version without PHP executing again and without MySQL repeating the query.

The fastest database query can be the query you do not have to make.

Likewise, the fastest PHP execution may be the PHP execution you do not have to repeat.

Containers and Cloud Computing

Modern applications may separate these technologies even further.

Nginx might run in one container.

PHP might run in another.

The database might operate as a managed cloud service somewhere else entirely.

Several copies of an application may run simultaneously behind a load balancer.

If demand increases, additional application instances can be started.

If one system fails, another may continue serving requests.

The single-server model has evolved into an architecture of cooperating services.

But Small Websites Do Not Need All of This

It is important not to confuse what is possible with what is necessary.

A modest website does not automatically need containers, clusters, multiple proxies, distributed databases, and complicated cloud infrastructure.

Complexity has a cost.

Every additional layer needs to be configured, secured, monitored, updated, backed up where appropriate, and understood when something goes wrong.

A simple, well-maintained server can be an excellent solution.

Good engineering means using enough technology to solve the problem—not adding complexity merely because the technology exists.

Security at the Web-Server Layer

Web servers also participate directly in security.

They can control which requests are permitted, restrict access to sensitive resources, enforce HTTPS, add security headers, limit request sizes, maintain logs, and reject certain suspicious requests.

Additional systems such as web application firewalls and intrusion-prevention tools can provide further layers of protection.

But once again:

No single layer provides complete security.

A secure web application depends on the web server, PHP application, database, operating system, network configuration, authentication, software updates, backups, and the people administering them.

Logs Tell the Story

One of the most valuable things a web server produces is something visitors rarely see:

logs.

Access logs can record requests reaching the server.

Error logs can record problems encountered while processing them.

Those records can help diagnose broken pages, missing files, application errors, suspicious requests, automated bots, and attacks.

When something goes wrong, logs often provide the evidence needed to understand what happened.

Apache and nginx Tomorrow

Will Apache still be serving websites decades from now?

Will nginx?

We cannot know.

But the jobs they perform will remain necessary.

Something must accept requests.

Something must establish secure connections.

Something must route traffic.

Something must decide whether a cached response is available.

Something must communicate with application software.

And something must return the result.

The software performing those jobs may continue evolving, but the underlying requirements remain.

What Will AI Change?

Artificial intelligence may increasingly help configure and manage servers.

AI can already help explain configuration files, examine logs, identify unusual patterns, troubleshoot errors, suggest performance improvements, and help administrators understand unfamiliar systems.

In the future, intelligent systems may automatically adjust capacity, detect problems, optimize caching, analyze attacks, and repair certain configuration issues.

But AI will not make server architecture irrelevant.

In fact, safely allowing automation to manage infrastructure makes understanding the underlying system even more important.

Someone needs to know whether the automated decision makes sense.

From One Program to an Orchestra

The early web could be beautifully simple.

A browser requested a document.

A web server sent it.

Today's web can look more like an orchestra.

A CDN may handle one part.

Nginx may handle another.

Apache may apply website-specific rules.

PHP-FPM may execute the application.

MySQL may retrieve the information.

A cache may eliminate unnecessary work.

A firewall may examine the traffic.

Monitoring systems may watch everything happening along the way.

Each technology has its part.

The visitor simply sees the page.

The Technology Can Become Invisible Without Becoming Unimportant

Once again, the theme of this series appears.

The visitor does not need to know whether nginx or Apache handled the request.

The visitor does not need to know whether PHP-FPM generated the page.

The visitor does not need to know whether MySQL retrieved the information.

They care that the website is fast, reliable, secure, and useful.

But for the people who build and maintain the web, understanding those invisible layers helps explain why the visible page works at all.

Next: Linux — The Operating System Beneath the Web

We have now worked our way through several important layers.

Apache and nginx can receive and route the request.

PHP can provide the application logic.

MySQL can provide the memory.

But all of that software needs an operating system on which to run.

For an enormous portion of the web, that operating system belongs to another remarkable open-source story:

Linux.

Next in The Technologies That Built the Web, we will go back to 1991 and explore how a university student's personal operating-system project grew into one of the most important foundations of the internet, servers, cloud computing, supercomputers, embedded systems, and modern technology.

Home
Brad Zehr | Zehr.net | brad@zehr.net

About Services Why A Site Site Ideas Topics Podcast Help Contacts

Topics, Podcast & Images on this site are AI Assisted.

Search Contact Home