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 6 - Blocks , lambda, procs and closure

 Blocks , lambda, procs  and closure Table of content  1. Blocks 2. Lambda 3. Procs 4. Closure Blocks  Ruby blocks are little anonymous functions that can be passed into methods. Blocks are enclosed in a do-end statement or between brackets {} 
. Blocks can have multiple arguments
. The argument names are defined between two pipe | characters. Blocks are typically used with ‘each’ method which iterates over a list. Syntax of block using {} ['List of items'].each { | block arguments|  block body }  Syntax of block using do-end ['List of items'].each do | block arguments |      # block body end Example of block declared as do-end with each method.   [ 1 , 2 , 3 ].each do |num| puts num end     Output   $ ruby block_with_each.rb 1 2 3 $    Blocks can also be saved in variables or passed as argument to another function.   yield is a Ruby keyword that is used to call a block. When you use the yield keyword, the code inside the block will run. Example of saving a bl