blog posts

Nginx

What is Nginx and its advantages and disadvantages and comparison with Apache

What is nginx web server?

Nginx, pronounced “engine-ex”, is an open source web server currently used as a Reverse Proxy, Load Balancer and HTTP Cache.

Many well-known companies such as Intel, Apple, Twitter, Facebook, Google, IBM and Microsoft are currently using Nginx. Nginx was first developed by Igor Sysoev in October 2004 with the goal of solving the C10K problem.

Because Nginx was built to improve the performance of web services, it often outperforms other popular web servers in benchmark testing. Especially if these tests are related to static content or a large number of simultaneous requests.

Reverse Proxy: In computer networks such as the Internet, reverse proxy is commonly referred to as a proxy server that is accessible from public networks.

Load Balancer: In computing, the process of distributing tasks over a set of resources to increase overall processing efficiency is called Load Balancer or Balanced Process Distributor.

C10K Problem: A popular term in the web with the theme of managing the performance of 10,000 concurrent connections.

How does Nginx Web Server work?

Nginx Web Server is built to manage a large number of concurrent processes with minimal memory usage. Instead of creating new processes for each web request, Nginx uses a concurrent, event-driven approach in which requests are processed in a single directory.

In fact, with Nginx, a Master Process can control several smaller workflows. In this way, the main process work is only the management of labor processes and the labor processes do the processing and the final order. Because the Nginx operating system is synchronous, any request can be made by labor processes, without interrupting other requests. The most important features of Nginx are:

  • Reverse proxy with cache
  • IPv6
  • FastCGI support with cache
  • Balanced distribution of processes
  • Use WebSocket
  • Manage static files, index files and automated indexing
  • TLS / SSL with SNI

FastCGI: A binary protocol that connects interactive applications to a web server.

WebSocket: A computer communication protocol that provides fully two-way communication channels through a TCP connection.

TLS / SSL: An encryption protocol designed to secure communications over a computer network.

SNI: stands for Server Name Indication, an add-on for the TLS computer network protocol.

Advantages and disadvantages of using Nginx

Advantages

  • Writing code on this web server is easier than competitors.
  • It is easy to configure and has a more modern design than other web servers.
  • It is event-oriented and allows you to manage multiple communications simultaneously.
  • Uses less memory and hardware resources.
  • It speeds up the site and helps you rank better on Google.
  • It is more compatible with web applications such as Ruby, Python, Joomla and..
  • Helps convert dynamic content to static content.
  • Allows you to manage thousands of simultaneous connections at a time.

Disadvantages

It has fewer support forums than Apache, but it has more uses than Apache.

It offers you fewer modules and extensions than Apache.

Why use Nginx?

There are many reasons to choose this web server. You can see the most important of them in the following list:

Provides a single entry point: With the environment provided by it, creating an entry point for users to access services is a better approach.

Storage: This web server provides cache for static and dynamic content, increasing performance.

Provide multiple back-end applications simultaneously: The cluster helps you to effectively manage the traffic of different applications, which is ideal for cloud service providers.

A / B testing capability: This web server utilizes A / B testing capability, which helps to deploy small applications.

Standard login capability: It uses the standard HTTP login format.

Scalability and balanced distribution of processes: The status of it allows you to scale the back-end infrastructure. Thus, adding or removing any element from the site will not affect the user experience.

0% chance of failure: It regulates the smooth operation of the web server and allows you to seamlessly update the system software without any disconnection.\

Reduce the likelihood of DoS attacks: The Nginx web server has gained a lot of popularity for managing and handling thousands of incoming HTTP requests or traffic and protecting application security while increasing site traffic.

Compare nginx and Apache usage statistics

Apache is one of the most popular open source web servers, which according to a reliable source W3Techs, is currently used by 43.6% of websites with known web servers (in 2018 this number was 47%). Nginx web server is in second place with a very small difference (41.8%).

NetCraft recently surveyed 233 million registered domains, with Apache using 31.54% and Nginx 26.20%.

While Apache is generally the most popular option among web servers, Nginx is more popular with the most visited websites. If you want to understand the power of Nginx, take a look at the list below:

  • 9% of the world’s 100,000 popular sites use Nginx. (This number was only 56.1% in 2018)
  • 1% of the world’s 10,000 most popular sites use Nginx. (This number was only 63.2% in 2018)
  • 1% of the 1000 most popular sites in the world use Nginx. (This number was only 57% in 2018)

In fact, Nginx is used by some of the world’s largest sites such as Netflix, Nasa and WordPress.com.

But the use of Apache is inversely related to the increase in site traffic, and usually sites that are not visited more often use Apache more. The following list can give you a better understanding of this topic:

  • 24% of the world’s 100,000 popular sites use Apache. (This number was 27.1% in 2018)
  • 8% of the world’s 10,000 most popular sites use Apache. (This number was 21.5% in 2018)
  • 6% of the world’s 1,000 most popular sites use Apache. (This number was 16.2% in 2018)

Also, if we look at Google search statistics, we see that since 2004, Apache name searches have been declining, while Nginx phrase searches have been steadily increasing.

How do we know if we are using Nginx or Apache?

On most sites, you can easily check which web server you are using via the HTTP Server header. By clicking on the network option in Chroma Devtools, you can view HTTP headers or get help from tools like pingdom or GTmetrix.

However, the HTTP header may not always show the main web server. For example, if you use proxy services such as Cloudflare on your WordPress site, the HTTP Server header will display the Cloudflare name.

Conclusion

In this article, we tried to cover the basics of Nginx, its brief history, its place in the server space, as well as the benefits of using Nginx. In general, Nginx is a web server that acts as an email proxy, reverse proxy, and balanced process distributor. Its structure is simultaneous and event-oriented to ensure the simultaneous processing of multiple requests and, most importantly, is easily scalable.