Nginx and Apache differences

I, Arslan Mirbzergi, intend to share my personal experiences with you. Onmywebsite,   you can see examples and practical projects and implement them in your own projects. In this section, we will briefly explain the important differences between Nginx and Apache.

In the 1990s era, the internet as we know it began its global “conquest.” If you summarize the entire “Web” protocol, it can be described as follows: A visitor asks the DNS and IP systems to forward a document request to the correct computer. The web page requested will be returned to the visitor via the computer hosting it.

HTML documents, in their most basic form, are what make up a website. A server program is required on the “serving” machine in order to provide visitors with various web pages. Nginx vs. Apache software handles requests, analyzes them, and then returns the corresponding documents to be viewed in a visitor’s browser.

1- Nginx vs. Apache

Web servers like Nginx and Apache are widely used to deliver web pages to a browser. From a WordPress site that is hosted on a third-party server, in our case. Here are some quick numbers:

  • Apache was first, then Nginx was released in 2004.
  • Large Fortune 500 firms around the world make use of both.
  • Nginx’s share of the web server market has been rising steadily for some time.
  • Nginx has a performance advantage in some situations.
  • Support \sApache
  • Since Apache was the first to be released, we’ll start there.

2-  Apache

CERN httpd and NCSA httpd, two early internet web servers developed by Tim Berners-Lee and released in the early 1990s, was quickly eclipsed by Apache, which was released in 1995 and quickly rose to prominence as the world’s most well-known web server. It’s still in that position today, but that’s largely due to historical factors. The Apache Foundation is responsible for the development and maintenance of Apache, which is available under a free license.

The origins of the name Apache are shrouded in mystery. However, there are two competing explanations: one is based on the famous Native American heritage, while the other claims that “Patchy Server” is an ironic reference to a server that had undergone a series of software upgrades.

2-1- Linux

Apache has a large share of the market because it’s pre-installed on all primary Linux distributions like Red Hat, Centos and Ubuntu.

Apache’s significance in the Linux world can be seen in the fact that the server process name for Apache is HTTPd, making Apache a noun.

Apache’s popularity is partly due to its configuration system and the. htaccess file it comes with as standard.

2-2- httaccess.

Apache for your Configuration of httaccess. uses. Given the many Flexibility that Apache provides for how Configure handles incoming requests, it’s about how Configure, edit and work with the httaccess file. There is also a lot of training. For example: various Redirection rules, maximum upload file size, URL overwriting, memory limitation, Directory protection (htpasswd), expired headers, cache-control headers, Encoding headers, cookies, manipulation of query strings.
Kinsta, on the other hand, uses Nginx, which uses htaccess files. Does not support. However, the settings and rules in the htaccess files can be easily translated into Nginx rewriting Syntax.
One of apache’s main “advantages” is that on the main server root or directory of the website, any Level or Directory in Directory tree can file httaccess. its own configuration.
For Shared hosting providers, this is a dream because they can support hundreds of users on the same system and configure how their websites are serviced without affecting each other. Customers can also configure a lot of details in a Limited Shared hosting environment without the overall configuration of the server.
As stated in the official documentation:
“In general, you should only use htaccess files if you do not have access to the server’s original Configuration file. Use.”
It has flexibility per htaccess files. It’s going to hit Performance, even if you don’t really use them!
Whenever the files htaccess. Enabled, Apache must traverse the entire Directory tree from the URL or file requested through all the higher levels to server’s root directory, and then load them for each request. It should then process these files and re-configure itself for each configure directory in this way.
With WordPress websites, things get quite complicated. A typical WordPress website can have hundreds of requests from different Directory. The /wp-content/uploads/yyyy/mm type usually loads several requests on one page, often consisting of directories of different months. Then there will be /wp-content/themes/parent-theme static resources and /wp-content/themes/child-theme resources, including JavaScript, CSS files and image. Then there are /wp-content/plugins with Static files downloaded from dozens of subcategory from sub-plugins, which for each of these resources, Apache for plugin searches must process its entire Directory tree.
An analysis has shown that a typical WordPress setting, which is not the typical setting for websites in Shared hosting, involves 42 separate htaccess implementations. And 249 separate searches for htaccess files. would be.
It’s only at web server level, and the visitor will still have to wait for PHP to run the entire WordPress Call stacks process and create a database request and give it to MySQL to assemble the web page and send it to the visitor.

2-3- Modules

The dynamic module system, which is another feature of Apache, has helped make it popular.

Nginx and Apache both offer modules as a way for users to extend the functionality of their web servers. Once the webserver has been installed and deployed, Apache lets users install modules and then enable or disable them as needed. The a2enmod and a2dismod commands in Debian-based distributions allow you to enable and disable these modules without editing any configuration files.

Compression, encryption, logging, redirections, and more advanced things like editing requests and responses with advanced syntax are all included in the official list of modules that come with Apache standard distribution.

3-  Nginx

Russian developer Igor Sysoev first released NGINX in 2004. It is also known as Nginx or NGINX. Nginx’s project manager, Owen Garrett, put it this way:

Because Apache web servers have performance issues, Nginx was created to solve those issues.

In 2002, the server was initially designed to help scale the website rambler.ru. Nginx is available in two flavors: open source with a BSD-style license and Nginx Plus, which adds support and enterprise-specific features.

Static file serving and load balancing in front of Apache installations were the most common uses for Nginx after it was released. A growing number of websites have switched from Apache to Nginx entirely as the web has matured, necessitating the need to squeeze every last drop of speed and hardware efficiency out of it.

F5 Networks paid $670 million for Nginx Inc. in March of this year. Approximately 1,500 paying customers were using the Nginx server at the time, according to Techcrunch.

According to w3techs data, Nginx’s market share has steadily increased for the past few years, pushing Apache out of first place.

According to this data on global web servers, Nginx has been among the top one million websites for some time now.

Google’s search process also reflects this fact:
Netcraft poll shows Nginx surpassed Apache in April 2019.

4-  Nginx Configuration

Because Nginx lacks an Apache-like configuration system, retail hosting providers rarely use it despite being much more efficient and fast. It does not perform as well as Apache in shared environments.

On the other hand, Nginx has a significant advantage over Apache because it does not allow directory-level configurations. Nginx wiki has a comparison of the impact on performance:

Nginx vs. Apache performance

Nginx Modules

Aside from the Nginx modules system, this makes it appear to be a higher-end option. To use Nginx modules, they must be enabled during the build process, requiring more technical know-how. This also makes adding modules after installation more difficult.

From 2016 on, things have changed, and only paying customers can access the official/verified dynamic modules repository. In May of this year, they announced that they would begin working on QUIC and HTTP/3 support.

Caching: Nginx vs Apache

For the sake of simplicity, think of caching as preparing the content for website visitors ahead of time so that when they “knock on the door,” you don’t have to go searching for the content they’re looking for. This simplifies the process. You’ve already prepared it and can give it to them immediately.

As with Apache, Nginx’s typical configuration was to sit between servers and end-users to reduce the overall infrastructure’s load. Static content can be cached in these circumstances, saving the protected origin server from being queried repeatedly.

Because Kinsta LXC containers run Nginx as a stand-alone web server, this isn’t an issue. When it comes to providing static content, Nginx does an excellent job all by itself.

Another issue to consider is whether to use a dynamic or static page cache. A WordPress website’s scenario implies that all WordPress pages generated for each URL are stored in memory or on disk in WordPress.

Nginx comes pre-configured with FastCGI caching enabled by default. It’s easy to use, but it has a lot of potential because it’s a lesser-known Nginx feature.

When comparing this to Apache’s mod_cache module, keep in mind that mod cache is notoriously buggy and incompatible with other modules. As a result, the Varnish HTTP accelerator is the default caching solution deployed with Apache. In spite of the fact that Varnish has long been the industry standard, recent tests show that Nginx caching has a distinct advantage over it.

While Nginx is used at Kinsta, we also use a proprietary caching plugin that provides fine-grained control over which pages are cached as well as Kinsta CDN’s static assets.

Handling Requests: Nginx vs Apache

Apache and Nginx differ primarily in their underlying architecture for handling requests.

As a result of MPMs or Multi-Processing-Module (MPM), Apache is able to handle a wide range of request types, including HTTP, HTTPS, FTP, and SMTP.

Prefork module is the oldest MPM, dating all the way back to Apache’s inception. Just this module’s poor performance is to blame for Apache’s bad reputation. Every request is handled by a new instance of Apache running in this mode.

A PHP interpreter was embedded in every process on the Apache server when this module was used in conjunction with mod PHP.

This was a waste of time. The Prefork module is installed by default with Apache. Additionally, it only allows HTTP/1 connections.

Later on, Apache developed the multi-threaded worker MPM and then the event MPM for parallel processing. Both of these solutions significantly improve Apache’s overall performance. By using PHP-fpm instead of. htaccess, Apache is able to remain a competitive solution today, but this defeats the purpose. htaccess.

Nginx employs an event-driven architecture that is asynchronous and non-blocking.

When it comes to Linux/Unix, processes are what actually run programs.

Threads are a subset of processes, and process execution can contain multiple threads. Think of it as having several windows open at once, each with its own set of tabs. Thus, multiple CPUs and multi-core, multi-thread CPUs can be used to speed up the execution of a program. You can learn more about the differences from Linus Torvalds.

For the sake of clarity, Apache uses processes for every one of these connections: (and with worker MPM, it uses threads). The more individuals using a service, the more costly it becomes.

Creating a new thread or process can be compared to the process of starting up a computer or running software. It takes time, even on the fastest computers. A single page load on many modern websites can generate hundreds of requests.

However, tests show that Event MPM cannot outperform Nginx in terms of optimization. Nginx can serve up to two times as many requests as Apache when it comes to static files.

Each CPU/core in Nginx should have a single Nginx worker process. Nginx worker processes differ in that each one can handle tens of thousands of incoming network connections. No new threads or processes need to be created for every connection.

Consequently, Nginx is critical for the content delivery of major Content Delivery Networks such as Cloudflare, MaxCDN, and our partner KeyCDN, or websites like Netflix

With Automattic, we’ll conclude this list of Nginx users. Automattic owns WordPress.com and many other websites.

WordPress.com’s load balancers were converted to Nginx by Automattic in 2008, and the entire server stack was migrated to Nginx.

The HTTP response headers are usually where we can find out what a live website is using. This means that we will have to right-click on a website and select Inspect, then select the network panel in the developer tools before reloading the page. We’ll be able to see everything that the website is loading at the same time. Any resource’s Headers tab will typically display server information if you select it. If the website makes use of a CDN, we might see something like Cloudflare Varnish in the server line.

Using cPanel, Apache, and PHP to host a WordPress website is an example of a typical shared hosting setup:

And this is a website in Nginx:
On the left, if we expand it, we can analyze the time of each source and see its impact on the load time of the page.

And in the end,

Nginx has gained more traction and attention as a web server because of the architectural differences between it and Apache, which I discussed in this article. These are the most important characteristics that set it apart in a competitive industry like ours, which is resource-intensive.

Apache or other tools like Lighttpd, IIS, LiteSpeed, or Caddy may be good solutions for different use cases with different priorities.

Kinsta uses Nginx as part of our WordPress and WooCommerce-optimized hosting solutions. All software resources needed to run a WordPress site are contained in an isolated container (Nginx, Linux, PHP, MySQL). The resources are solely yours, and they are not accessible to anyone else.

Leave A Comment

29 − 20 =

Please Send Email

Your message sent successfully
There has been an error