Nginx

Brief Introduction

Nginx ("engine x") is an open-source HTTP web server that since its initial success is also used as reverse proxy, load balancer, TCP/UDP proxy server, mail proxy server and content cache. 

It was originally written by Igor Sysoev and distributed under the 2-clause BSD License (open-source permission license) and publicly released in 2004. A company of the same name was founded in 2011 to provide support and NGINX Plus, a paid software. 

Enterprise distributions, commercial support and training are currently available from F5 Inc. that acquired the company in 2019. 

This server was initially developed as a solution to the C10k problem (the problem of optimizing computer networking stacks to handle large amounts of concurrent connections).

How it works? 

NGINX is event-driven and asynchronous. It usually spawns a fixed number of worker processes (often equal to the number of CPU cores). One single worker process handles thousands of concurrent connections simultaneously using multiplexing (epoll/kqueue). It does not start a new process for every new task/request. 

  • Workers accept new requests from a shared listen socket and execute highly efficient run loops inside each worker to process thousands of requests.
  • The shared listen socket represents a feature that enables use of the SO_REUSEPORT socket option, which is available in newer versions of many operating systems, including DragonFly BSD and Linux (kernel version 3.9 and later). This socket option allows multiple sockets to listen on the same IP address and port combination. The kernel then balances incoming connections across the sockets.
  • Masters read and validate configurations by creating, binding and closing sockets. They also deal with handling of starting, terminations, and maintaining the number of configured worker processes.
    The master node can also reconfigure the worker process with no service interruption.
  • Proxy caches are special processes. The Cache Loader and Cache Manager are special processes used to handle proxy caching. The cache loader checks the disk cache item and populates the engine’s in-memory database with the cache metadata. It also prepares the NGINX Instances to work with the files already stored on the disk in a specifically allocated structure. The cache manager handles cache expiration and invalidation. 

Advantages

One of the main advantages to using NGINX is that it reduces the waiting time to load a website. You need not worry about high latency on your websites, therefore providing a good user experience. 

Nginx also speeds up performance by routing traffic to web servers in a way that it increases the overall speed of the process which provides a good browsing experience to users. Nginx can also act as an inexpensive load balancer. 

Moreover, it offers scalability and ability to handle concurrent requests. Nginx also allows for updates on the spot without downtime. 

Its versatility is one of the main reasons that it's widely used and favored amongst developers. It’s most commonly used as a web server due to its swift performance and scalability however as already mentioned it can also be used as a reverse proxy server by directing the client’s request to the appropriate back-end server. 

It can act as a load balancer - it can automatically distribute network traffic load once the upstream servers are configured.

Another use case is as an API gateway - this is useful for request routing, authentication, and exception handling. 

Additionally, it can be used as a firewall for web applications by filtering incoming and outgoing network requests to your server. 

It can act as a cache that can help you store your data for future requests and it can protect against distributed-denial-of-service (DDoS) attacks 

In addition to all of this, it can be set up into the K8s (Kubernetes) environment.

Disadvantages 

As expected, every system also has its disadvantages. Both maintenance and setup require expert knowledge so again this system might have a steeper learning curve for newbies.

Although NGINX itself is free of charge, there’s also a paid version called Nginx Plus, an all-in-one load balancer, content cache, web server and API gateway, and microservices proxy that comes at a certain cost. 

Given these minor disadvantages, the overall versatility and scalability of Nginx are enough of a reason for this web server software to be widely used and preferred amongst the developers community.

Key Takeaways

  • Nginx is an open-source HTTP web server that can be used as load balancer, a reverse proxy server, content cache, mail proxy, and a firewall tool. It’s highly versatile.
  • It has a master-worker architecture and uses non-blocking, asynchronous, event-driven mechanisms. 
  • It uses multiplexing, meaning a single worker process can handle thousands of concurrent tasks without blocking.
  • Each worker is a single-threaded process that accepts new requests from a shared listen socket.
  • Masters read and validate configurations by creating, binding and closing sockets.
  • Proxy caches have special processes - cache loader and a cache manager. The cache loader checks the disk cache item and populates the engine’s in-memory database with the metadata cache. The cache manager handles the cache expiration and invalidation.
  • Despite its steeper learning curve and operational complexity, as well as occasional performance challenges, NGINX remains widely recognized and used for its speed, scalability, flexibility and ability to handle massive concurrent traffic.

Address

3 Sluntse str., Veliko Tarnovo, Bulgaria

Contacts

Please Enter Name
Please Enter Surname
Please Enter Email
Email is invalid
Please Enter Message