Why is Nginx better than apache server

NGINX vs Apache: The popular web servers in comparison

The Internet as we know it today began its campaign of conquest in the early 1990s. On September 20, 1990, the world's first website went online at the CERN nuclear research center in Geneva, and at the same time heralded the birth of the World Wide Web. In principle, websites are nothing more than HTML documents. In order to be able to make several different websites available to visitors, the host needs server software. This processes the requests and analyzes them in order to then return the requested documents in the browser. Two of the most popular programs of this type are NGINX and Apache. In this comparison, we will introduce you to the two web servers and their features in detail and show which of them is better suited for which purposes.

How does a web server differ from an application server?

The task of a web server is to establish a connection between a physical or cloud server and the stored websites (or browsers) of the Internet users. The application server, on the other hand, is responsible for making applications available within a network.

Are both NGINX and the Apache web server suitable for processing dynamic queries?

No, in contrast to the Apache web server, NGINX only supports the delivery of static content. Dynamic content, on the other hand, is passed on to other software.

Can the two web servers also be used together?

Yes, it works extremely well. In practice, you will mainly find the combination NGINX as a reverse proxy and one or more Apache servers in the backend.

content

1. Apache: Popular Flexibilist

The open source web server Apache has been on the market since 1995 and, according to w3techs.com, is the most widely used web server of all. Due to its long history, extensive documentation and flexible application options, the web server is very popular with administrators. The enormous market share is primarily due to the fact that many systems (e.g. CMS) work with Apache by default. It is also preinstalled on all major Linux distributions such as Red Hat, CentOS or Ubuntu.

Good to know: The Apache Software Foundation has been developing the web server since 1999.

The Apache web server is configured using an .htaccess file. This allows a high degree of flexibility when processing incoming inquiries. For example, you can define storage limits and file upload restrictions, set up redirection rules or directory protection (htpasswd) or make various security settings for handling cookies.

One of the greatest advantages of Apache is that you can assign a separate .htaccess file with an individual configuration to each level or directory in the tree. This allows shared hosting providers, for example, to offer their customers a configuration option for their website on one and the same machine without affecting other users. If a user makes a setting for his dedicated environment, the global server configuration remains unaffected.

1.1. Modules extend the functionality of the web server

Thanks to the dynamic module system (which is also available in this form in NGINX), the functionality of Apache can also be expanded. You can still install the modules when you have set up the Apache web server and put it into operation, and you can activate or deactivate them as required. An official list of all modules that are part of the Apache standard distribution can be found here.

Tip: In Debian-based Linux distributions, the modules can be accessed without editing the configuration files using the commands a2enmod and a2dismod activated or deactivated.

1.2. NGINX vs Apache: Suffering from performance

The Apache web server has been continuously improved over time and its performance has been optimized. However, it does not come close to NGINX's performance benchmark.

A major weak point of Apache is its performance. Because while the web server is still running reliably and stably on smaller websites, it regularly stumbles with an increasing number of simultaneous requests. This is mainly due to the fact that a separate process is started for each open connection to the web server, which uses memory. As a result, there are logically just as many processes with hundreds or thousands of parallel requests. These increase the loading times of the pages drastically and in the worst case can even lead to a complete standstill of the web server.

The Apache web server has been continuously improved over time and its performance has been optimized. However, it cannot keep up with an NGINX “out-of-the-box”.

2. NGINX: high-performance lightweight

NGINX was only released in 2004 and developed from the start with a focus on performance, the core server and the proxy functions. The web server offers decisive advantages over Apache, especially on limited systems, because it relies on an asynchronous, event-based architecture. This means that a separate process is not started for each connection, but several thousand connections can be handled per process. In this way, NGINX is able to handle a large number of simultaneous requests without sacrificing speed and stability. The resource consumption remains relatively constant even during peak loads, which means that high-performance pages with a large number of accesses are also delivered with limited hardware (e.g. on a Raspberry Pi).

2.1. Dynamic content is not supported

NGINX can also be expanded with modules. However, these have to be compiled into the system, as dynamic loading as is the case with Apache is not possible. In addition, in contrast to Apache, NGINX only supports the delivery of static content, such as images, CSS stylesheets or JavaScript, and also does not offer the possibility of integrating corresponding interpreters through modules. For dynamic content (e.g. PHP, Python or Perl scripts), the requests are passed on to another software (i.e. in the case of PHP to the corresponding interpreter).

In addition, no configuration adjustments at directory level (through .htaccess) are supported, which means that setting up an NGINX web server is generally a bit more complex than with Apache. However, this only matters if you want to deal with the server administration in detail. Hosting providers who have NGINX in their portfolio usually have the right modules for common tasks.

3. NGINX and Apache as a network

In the WordPress environment in particular, you will often find the combination of an NGINX reverse proxy and one or more Apache backend servers.

In order to benefit from the advantages of both worlds, you can also use NGINX and Apache in combination. While NGINX is particularly suitable as a reverse proxy, for example, Apache is primarily used as a backend server due to its handling of dynamic content.

In practice, this is done by placing the NGINX server in front of one or (as a load balancer) several Apache servers. The incoming connections first go to the NGINX, which takes care of the delivery of the static content. For dynamic content, however, the request is passed on to the Apache server, which can also access its .htaccess file in this context.

4. Conclusion: Apache or NGINX?

There is no general answer to the question of which web server is the better one. Because while NGINX Apache is miles ahead of the rest in terms of performance, it has the edge when it comes to handling dynamic content. The decision ultimately always depends on the individual requirements of your web project. In practice, many users also rely on a network in order to benefit from the strengths of both web servers.

Good to know: The Internet community "Stack Overflow" is a good place to go for developers and administrators. Because there you will not only find answers to most questions about web servers, but also numerous instructions, tutorials and support information with regard to setting up and using Apache, NGINX and their alternatives. These include, for example, the free web server Lighttpd or the open source HTTP / 2-capable Caddy.

The advantages and disadvantages of the two web servers can also be found in the following video:

30 ratings

Ø 4.30
NGINX vs Apache: The popular web servers in comparison
4.3530Loading ...