Skip to main content

Beginners guide to NGINX Part 1 - Introduction

 

Beginners guide to NGINX

Table of content 

  1. Introduction
    • Apache Web Server
    • NGINX
    • Multiplexing and Demultiplexing

Introduction

NGINX is a web server, used to serve web pages over the internet, that also works as a reverse proxy, load balancer and caching and caching device. NGINX is pregerred for its single threaded, event-driven and master-slave architecture.
 
Let is understand the traditional apache web-server architecture.

Apache web server architecture  

 

Apache also known as HTTPD is an open source web server that follows a process driven approach and creates a new thread for each new request. 

The MPMs (Multi-Processing Modules) in Apache, provides a flexible architecture for choosing different connections and different handling algorithms. 

The three main Apache MPMs are: 

1.Process (Pre-fork) MPM

2.Worker MPM

3.Event MPM 

By default, Apache is configured in Pre-fork mode (mpm_prefork). It responds to a set number of processes, each of which can serve a single request at a time.

In other words, Apache creates a new thread every time to handle each connection request.

However, Apache’s basic architecture can lead to heavy resource consumption, thereby, can cause issues with the server (eg- slow speed).

NGINX 


NGINX employs an event-driven architecture and deals with the requests asynchronously.

It was designed to use a non-blocking event-driven connection handling algorithm.

Thus, its process can handle thousands of connection (requests) within one processing thread. It uses the concept of Multiplexing to achieve this. 

NGINX has sliced into three different parts. They are

  • Master:

NGINX follows the master-slave architecture. The Master will allocate the jobs for the workers as per the request from the client. Once the job allocated to the workers, the master will look for the next request from the client that’s it won’t wait for the response from the workers. Once the response comes from workers master will send the response to the client. 

  • Worker: 

Workers are the slaves in the NGINX architecture, will heed to the Master. Each worker can handle more than 1000 request at a time in a single-threaded manner. Once the process gets done, the response will be sent to the master.  

  •  Caching

NGINX cache is used to render the page very fast by getting from cache memory instead of getting from the server. The pages are getting stored in cache memory on the first request for the page.

Multiplexing and Demultiplexing

 

Multiplexing it generally referred to the process and techniques of transmitting multiple analog or digital input signals or data streams over a single channel. 

Demultiplexing(Demuxing) is the rever of the nultiplexing process and it involves reconverting a signal containing multiple analog or digital signal streams back into the original separate and unrelated signals.

Thank you folks.

 

Most viewed

Ruby on Rails Part 4 - Exception Handling

  Ruby on Rails Part 4 - Exception Handling  Table of content Exception Handling retry raise ensure else  catch and throw Exception classes Exception Handling Enclose the code that could raise an exception with a begin/end block and use rescue clauses to tell Ruby the types of exceptions that you want to handle. The syntax for exception handling : 
 begin  
      #- statements
 rescue OneTypeOfException       #-
 handle the exception rescue AnotherTypeOfException       #- 
handle the exception else       
# Other exceptions
 ensure 
      # ensure block is always executed
 end 
 Everything from begin to rescue is protected 

in the block. 
If an exception occurs during the execution of this block of code, control is passed to the 

block between rescue and end.
 
For each rescue clause in the begin block, Ruby compares the raised Exception against each 

of the parameters of the...