How does Apache Vs Nginx choose the best web server for you?

In this article, I will discuss in detail the difference between Apache and NGINX servers. Which is the fastest web server? What are their main advantages and limitations? Which one should you go?

The main difference between Apache and NGINX is its design architecture. Apache uses a process-driven approach and creates a new thread for each request. NGINX uses an event-driven architecture to handle multiple requests in a thread.

What is the Apache HTTP server?

Apache HTTP server is an open source cross-platform Web server, also known as "httpd" and Apache. He is the Apache Software Foundation managing its brand and services. The server is developed and maintained by the open developer community under ASF. Apache mainly runs on Linux, it supports 46% of the world's websites. It is a key component of the LAMP (Linux, Apache, MySQL, PHP) stack.

What is NGINX web server?

What is NGINX? Pronounced? It is pronounced "Engine X". It is a Web server released by Igor Sisoyev in 2004. Today, it is more than just a web server! At first, people mostly used Nginx as a supplement to Apache. It was mainly used to provide static files, but today, it has evolved into a complete web server that handles the entire web server task. Nginx is often used as a reverse proxy, load balancer, mail proxy, and HTTP cache. Both Apache and Nginx are the most common web servers for Linux. Together, they provide services for more than 50% of network traffic.

Although Apache and NGINX have many common qualities, they are different in many ways. Each excels in its own way and has its own purpose and program. In order to understand the differences and draw conclusions, let us go through the following detailed, end-to-end comparison. We also mention the winner of each comparison point at the end of each point.

Basic architecture

When it comes to Apache and Nginx, the fundamental difference lies in their design architecture. This means that they actually handle connections and traffic in different ways and respond to different traffic conditions. One is a process-driven approach, and the other is an event-driven architecture.

Apache

process-driven method

creates a new thread for each request.

Apache uses a multi-threaded approach. It provides various multiple processing modules. These pre-modules are basically three types of request processing algorithms. Each is used for different server needs. MPM (Multi-Processing Module) provides a flexible architecture for selecting different connections and different processing algorithms. In addition, different versions of Apache 2 use different parade modules. The three main Apache MPMs of

are:

1. Process (prefork) MPM

2. Worker MPM

3. Event MPM

By default, Apache 2.2 is configured for prefork mode (mpm_prefork). It responds to a set of processes, and each process can handle a single request at a time. In other words, Apache creates a new thread every time to handle each connection request. The

thread is the smallest sequence of programming instructions that can be independently managed by the scheduler. In most cases, threads are components of the process. However, the basic architecture of Apache may cause a lot of resource consumption, and therefore, may cause server problems (such as slow speed).

Nginx

event-driven method

handles multiple requests in one thread

Nginx uses an event-driven architecture and processes requests asynchronously.

It aims to use non-blocking event-driven connection processing algorithms. Therefore, its process can handle thousands of connections (requests) in one processing thread. This connection process module enablesNginx can work fast and wide with limited resources.

In addition, you can also use Nginx on low-power systems and systems running under heavy loads. Winner of

:

NGiNX-Its structure is lightweight and its architecture is much faster than Apache.

Yes

In the case of Apache vs Nginx, the two web servers handle static and dynamic content in different ways. They say that Nginx is better at handling static content, let's see if this is true!

static content

Apache

uses a file-based method to provide static content

static content or files are usually files stored on the disk on the server computer, such as CSS files, JavaScripts files, or images. Apache uses its traditional file-based approach to handle static content. When

Nginx

provides static content, Nginx is the big brother.

Because Nginx's design architecture is more capable of handling load, it is much faster in providing static content. According to a benchmark test of up to 1,000 simultaneous connections, its performance is 2.5 times faster than Apache. Nginx serves static resources, and PHP does not need to know this. On the other hand, Apache handles all these requests with expensive overhead. This makes Nginx more effective and requires less system resources. The small image

shows requests for static content and is processed in seconds. Nginx clearly surpasses Apache here!

dynamic content

Apache

handles dynamic content in the server

Apache can process dynamic content in the Web server itself without relying on any external components. So, it can handle your own. Talking about Apache vs Nginx performance: Nginx (if not better) is almost equal when considering dynamic content processing.

Below is a comparison of the number of requests for dynamic content. It doesn't seem to make a difference.

Nginx

does not handle dynamic content

It does not handle dynamic content. When it comes to dynamic content, Nginx cannot handle dynamic content in a Web server like Apache. All requests with dynamic web content are passed to an external process (such as PHP-FPM) for execution. Nginx waits for the final content to return and deliver to the client. Please refer to this picture for a clear idea:

When used with SCGI handlers and FastCGI modules, NGINX can provide services for dynamic content.

Winner:

Static: In terms of static content, Nginx outperforms Apache.

dynamic: Both are good at handling dynamic content.

operating system support

operating system support may be an important point to consider, especially when comparing Apache and Nginx. However, the two are almost similar here.

Apache

supports all Unix-like systems, including Linux and BSD

. It fully supports MS-Windows

Apache runs on various Unix-like systems (such as Linux or BSD), and it fully supports Microsoft Windows.

Nginx

supports almost all the same operating systems as Unix,

partially supports Windows.

It also runs on several modern Unix systems and has some support for Windows, but its Windows performance is not as powerful as other platforms.

Winner:

Apache stands out here~

distributed/centralized configuration

Apache vs Nginx is a well-deserved topic. Their configuration makes them different from each other and makes them equally interesting. Let us see whose configuration is easier and faster.

Apache

allows other configurations based on each directory through the .htaccess file.

This architecture allows non-privileged users to control certain aspects of their website without granting them permission to edit the main configuration. This is huge!

Nginx

does not allow other configurations

On the other hand, it has a disadvantage. It does not provide other configurations. However, it benefits you because it increases performance. By disallowing directory configuration, it can serve requests faster than Apache. It does not need to search for .htaccess files and interpret user-made reqs. Winner of

:

If the configuration is considered, Apache

if the speed is NGinx.

Request for explanation

In the Apache vs Nginx debate, explaining the request method is an interesting topic for comparison. They all process and interpret requests in completely different ways. Their different methods make them unique and also make one a little better than the other. Let's explore it!

Apache

passes the file system location through the file system location

, providing the ability to interpret the requirements. The physical resource as the location of the file system may require a more abstract assessment. It passes the request as the file system location. Of course, Apache does use URI locations, but they are usually used for more abstract resources. When creating or configuring virtual hosts, Apache uses the directory block under the document root. You can also see this preference for file system location when

uses .htaccess files to overwrite specific directory configurations.

Nginx

uses the URI to explain the request

Nginx is created as a Web server and a reverse proxy server. Due to these architectural requirements, Nginx mainly uses your eyes. Convert to the system if necessary.

It does not provide a mechanism for specifying configuration. For file system directories, the URI itself is passed. Passing the request (URI) instead of the file system location allows Nginx to easily run on the Web and proxy servers. It is simply configured by how the layout responds to the difference request pattern.

will not check the file system until it is ready to process the request. It explains why it does not implement any form of .htaccess file. The

design of interpreting requests as URI locations enables Nginx to not only easily act as a web server, but also as a proxy server, load balancer, and HTTP cache. In addition, in the Apache vs Nginx competition, NGINX once again won the transfer rate (the speed at which data is sent from the server to the client). In most cases, Nginx wins with a fair amount of 500/100.

Winner:

It seems that Nginx has won because of its faster interpretation and response. The

functional modules

are both expandable through the module system. But their way of working is different. Let us compare the functional modules of two web servers: Apache vs Nginx!

Apache

60 dynamically loadable official modules, which can be turned on/off.

Apache server has a rich set of functions, which can be enabled by installing one of the 60 official modules. There are many other unofficial modules that can be easily found on the Internet.

its moduleThe system allows you to dynamically load or unload modules to meet your needs. Its modules can be turned on or off to add or remove functions and connect to the main server.

In short, Apache has several functional modules to meet your needs, but many modules are not used frequently.

Nginx

third-party core modules (not dynamically loaded)

On the other hand, Nginx is selected and compiled into a third-party plug-in process. Cannot be dynamically loaded. These modules are useful, but they allow you to decide what to get from the server by including only the functions you want to use.

It is considered to be much more secure than the Apache server because any component can be connected in the server.

In addition, NGINX also provides all the core functions of a web server without sacrificing the lightweight and high-performance features required for success. Apache is like Microsoft Word and Nginx is like Notepad. Apache has a million options, but you only need a few. Nginx does these "several" things, doing them 50 times faster than Apach.

Winner:

NGiNX-Less important functions and modules make it a lighter, smarter, and better Web server than Apache.

Flexibility

Flexibility is one of the most important issues of Web servers. Apache vs Nginx has some interesting differences in flexibility.

Apache

supports custom web server through dynamic module.

can customize the Web server through the riding module. Apache's dynamic module loading time is the longest, so all Apache modules support this feature.

Nginx

is not flexible enough to support dynamic modules and load

. However, this is not the case with NGINX. In early 2016, NGINX gained support for dynamic module loading; previously, NGINX required administrators to compile modules into NGINX binaries. Most modules do not yet support dynamic loading, but over time, they may support dynamic loading.

winner:

Apache-it clearly leads at this point.

Security All

Apache vs Nginx security has once again become a topic of debate. Well, both of these web servers provide excellent extended security for C-based code bases.

Apache

is very safe

Apache ensures that all websites running on its servers are safe and free from any harm and hacker attacks. Therefore, it provides configuration hints for DDoS attack processing, and mod_evasive module for responding to HTTP DoS, DDoS, or brute force attacks.

NGINX

achieves better security with minimal code

However, NGINX's code base is significantly smaller by several orders of magnitude, so from a forward-looking security perspective, this is definitely a big advantage. NGINX also lists recent security recommendations. Read an article about defending against DDoS attacks on the Nginx blog.

winner:

Nginx-considered safer

support

support is what every customer desires. It can change or destroy your user experience. When comparing Apache and Nginx support, there doesn't seem to be much difference.

Apache

community support is done through mailing lists, IRC and Stack Overflow.

Commercial Apache support can be obtained from many third-party companies, such as OpenLogic, but the Apache Foundation does not maintain an official list. The Apache server is designed to provide strong support to all its users.

Nginx

passMailing lists, IRC, stack overflow, and forums provide community support

The company behind NGINX offers a commercial product called NGINX Plus, which supports a set of additional features related to load balancing, media streaming, and monitoring.

Winner:

This is a tie, and the support for both is almost the same. Both web servers are great.

Ultimately

Apache and Nginx cannot be replaced by each other, they have their strengths and weaknesses. After understanding the benefits, limitations, and differences, you may already have an idea of ​​the best web server for you. In

's post about Apache vs. Nginx, 5 out of 9 points were won by Nginx, and 2 points were "tie" by Apache and nginx. Therefore, we can clearly see that NGINX is ahead of Apache. When did

choose

? Still confused which server is more suitable for your solution? Let us know-when to choose! When did

choose Apache instead of Nginx?

1.Apache.htaccess

NGINX does not support .htaccess files similar to Apache. However, with Apache, you can gain the advantage of giving unprivileged users control over some important aspects of their website.

Obviously, users are not allowed to edit the main configuration.

uses .htaccess files, which can override system-wide settings on a per-directory basis.

For best performance, please include these .htaccess directives in the main configuration file.

In a shared hosting environment, Apache works better because of its .htaccess configuration.

P.S. Keep the best choice for dedicated hosting or VPS Nginx.

2. In the case of limited functions, there are some very important core modules using Apache

Nginx. However, Nginx has some functional limitations.

If there are certain restrictions or need to use additional modules that Nginx does not support, you may need to choose Apache instead.

When to choose Nginx instead of Apache

1. Fast static content processing

Nginx can perform better work in handling static files from specific directories.

In addition, the upstream server process will not be blocked because of a large number of static content requests because Nginx can handle them at the same time. This significantly improves the overall performance of the back-end server.

Nginx constantly strives to provide users with a better experience. In 2018, it showed significant growth. Check out the main highlights of 2018 on the Nginx blog.

2. Very suitable for high-traffic sites

. If we talk about the speed and how many customers can be served under high load, Nginx will always shine as a winner over Apache.

This makes Nginx significantly lightweight and very suitable for server resources. This is why most web developers prefer Nginx to Apache.

In particular, today's e-shops employ a Magento developer who knows how to work on high-traffic websites and is good at working on Nginx.

In short, when it comes to serving a website with a lot of traffic, Nginx is unmatched.

or both

Yes, Apache and Nginx can also be friends! By using the advantages of each server together, you can use them.

You can use Nginx in front of Apache as a server proxy (as shown in the figure below). This takes advantage of the fast processing speed of Nginx and the ability to establish a large number of connections at the same time.

For static connections, Nginx willFast service to the client. For dynamic content, such as Php files, the Nginx reverse proxy server will proxy their requests to Apache, and then Apache can process the results and return the rendered page.

Then, Nginx can deliver the final content to the client. In addition, it allows you to have a very practical web server to serve your customers (large number of users) very fast.

After

decide which web server you will use, Nginx or Apache is an important step in setting up a website. Both of these two solutions can handle different workloads and cooperate with other software to provide a complete Web stack.

original: http: //8nn.co/cqYJ

Author: Kavya

Translator: Ni Jiaxing