What Is Nginx? What It Is and How It Works

What Is Nginx? What It Is and How It Works



NGINX, which is pronounced as?‘engine ex,’ is a widely used open-source web server software. It was a project started by Igor Sysoev in 2002. It got officially released in October 2004. It was created to solve the problem of C10k, which is defined as a challenge to manage the ten thousand connections all at the same time.

What is NGINX?

NGINX is a web server but commonly used as a reverse proxy. It can be scaled efficiently as a web server as well as a reverse proxy. It does not allow you to allocate a process to a particular connection, but it creates a process pool that can be easily shared among multiple connections within the network. Whenever a request is made, a resource will be allocated to the process resulting in better resource utilization that can easily handle extensive connections.

NGINX also helps in setting up a secured connection between your data-centers and the outside network. It also works well as an HTTP load balancer that allows you to use multiple different load-sharing mechanisms.

Advantages of using NGINX

  • The written code base is more consistent than other alternatives.
  • It provides a friendly configuration format and has a modern design than any other web server alternatives.
  • It is event-based and allows you to handle multiple connections without having overhead due to the context switching.
  • It uses less memory and resources.
  • NGINX makes the website faster and helps them to get a better Google ranking.
  • It shows compatibility with commonly-used web applications like ruby, python, Joomla, etc.
  • It helps in transforming the dynamic content to static content.
  • It helps in handling thousands of concurrent connections at the same time.

Disadvantages of using NGINX

  • It comes with small community support as compared to Apache but has more use cases than Apache.
  • It does not offer you many modules and extensions as compared to Apache.
  • Due to small community support, it is less like to be preferred.


How Does Nginx Work?

Nginx is built to offer?low memory usage?and high concurrency. Rather than creating new processes for each web request, Nginx uses an asynchronous, event-driven approach where requests are handled in a single thread.

With Nginx, one master process can control multiple worker processes. The master maintains the worker processes, while the workers do the actual processing. Because Nginx is asynchronous, each request can be executed by the worker concurrently without blocking other requests.

Some common features seen in Nginx include:

  • Reverse proxy with caching
  • IPv6
  • Load balancing
  • FastCGI support with caching
  • WebSockets
  • Handling of static files, index files, and auto-indexing
  • TLS/SSL?with SNI

Nginx vs Apache Usage Stats

Apache?is another popular open-source web server. In terms of raw numbers, Apache is the most popular web server in existence and is used by 43.6% (down from 47% in 2018) of all websites with a known web server,?according to W3Techs. Nginx comes in a close second at 41.8%.

Netcraft ran a?survey?across 233 million domains and found Apache usage at 31.54% and Nginx usage at 26.20%.

No alt text provided for this image

While Apache is the most popular overall option,?Nginx is actually the most popular web server among high-traffic websites.

When you break down usage rates by traffic,?Nginx powers:

  • 60.9% of the 100,000 most popular sites (up from 56.1% in 2018)
  • 67.1% of the 10,000 most popular sites (up from 63.2% in 2018)
  • 62.1% of the 1,000 most popular sites (up from 57% in 2018)

In fact, Nginx is used by some of the most resource-intensive sites in existence,?including Netflix, NASA, and even WordPress.com.

Apache’s usage, on the other hand, moves in the opposite direction as a site’s traffic increases. It powers:

  • 24.0% of the 100,000 most popular sites (down from 27.1% in 2018)
  • 18.8% of the 10,000 most popular sites (down from 21.5% in 2018)
  • 16.6% of the 1,000 most popular sites (up from 16.2% in 2018)

If we take a look at?Google Search terms?since 2004 we can see that Apache has been on a steady decline, while NGINX has seen slight growth.

No alt text provided for this image

Again, when you consider that NGINX performs better under scale, it’s not surprising that high-traffic websites opt for NGINX over Apache. Check out our more in-depth comparison of?Nginx vs Apache.


Why use NGINX?

You can use NGINX for many reasons, and some of them are mentioned below.

  • It provides a single entry point-?within the containerized environment, you can deploy or destroy the containers whenever required, but having a single entry point for the users to access the services is a better approach. NGINX is a better solution to provide it. You can NGINX servers at your disposal that will help you to load the balance and route the traffic with a stable public IP address. NGINX server will get the user’s request and then forward it to the appropriate container.
  • Caching-?NGINX server provides a cache for both static and dynamic content, which enhances the performance. It will cost you to route each request for data to the microservice that generates it. You can implement microcaching to cache the data for a short period, reducing the back-end infrastructure load. It helps insulate the applications during high traffic to run smoothly without scaling the resources on a second basis.
  • Provide multiple backend apps-?NGINX cluster helps manage the traffic for various applications efficiently, thus preferred by many cloud providers. NGINX server is used to proxy the incoming traffic for individual HTTP endpoints that will route each request to the appropriate services. It also allows you to update rules without having any downtime and make the NGINX instance available even for complex applications.
  • A/B Testing-?NGINX comes with A/B testing features that help in rolling out the microservices applications. With NGINX, you can easily split the incoming traffic among many destinations. Whenever you deploy a new microservice, you can split the traffic and route some of the users to this application. This allows you to monitor the traffic and measure the KPIs to feel the difference in how both the versions are handling the real-time traffic.
  • Consolidated logging-?NGINX comes with standard HTTP log format. It allows you to log the complete web traffic on the NGINX front end rather than having a separate log for each microservice traffic and merging them later. Using NGINX, you can reduce the complexity of creating and maintaining access logs.
  • Scalability and fault tolerance-?the load balancing, health checks features of NGINX allow you to scale your back-end infrastructure so that adding or removing any microservice will not impact the user’s experience. If you want to deploy more microservices, you only have to inform the NGINX server that you have added a new instance to the load-balanced pool. In case of a failed instance, NGINX will not route the traffic to that instance until it recovers.
  • Zero downtime-?NGINX ensures smooth working of the webserver. You can even update or upgrade the system software seamlessly without interruption to the connection and avoid any application downtime.
  • Mitigate DoS attacks-?NGINX is well-known for handling tons of incoming requests or HTTP traffic, ensuring application safety during high traffic, common cache response, and deliver request smoothly. NGINX works as a shock absorber for your application. It also controls traffic that will protect the vulnerable APIs and URLs from being overloaded with requests. This can be achieved by applying a concurrency limit and queuing requests to avoid overload of the server.



How to Check If You’re Running Nginx or Apache

On most websites, you can simply check the?server?HTTP header to see if it says Nginx or Apache. You can see HTTP headers by launching the network tab in Chrome Devtools. Or you can check headers in a tool like?Pingdom?or?GTmetrix.

However, the HTTP header might not always reveal the underlying web server. For example, if your WordPress site is behind a proxy service such as Cloudflare, the?server?HTTP header will then say cloudflare instead.

No alt text provided for this image
Harsh Soni

Building @CrysPay on Aptos | ?? @RouterProtocol | Degree-ing ?? | Flutter + Web3?? | Pythoneer | DappDev | Sanskrit ????????| Contributor @PSF |

2 年

??????

回复

Nanfack Tadonke Arsene Parfait Have a look remenber the project....

回复

Thanks for posting

回复

Very informative post. ????

回复

要查看或添加评论,请登录

Omar Ismail的更多文章

社区洞察

其他会员也浏览了