Beginners guide to NGINX
Table of content
- 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