DEV Community

Shraddha
Shraddha

Posted on

A dive in nginx!

What is a webserver?In simple words it serves the request received from a client using the hardware its hosted on and the software being used.

So processing the request can be done in various ways right? Here comes the roles of different structures,and different types of webservers who have their own way of handling the request.Here are the main players namely apache, nginx,IIS Litespeed Openresty, Caddy etc.

I have elaborated nginx and its working in this blog,and soon will focus on the others as well.

Features:
Asynchronous, Event-Driven Architecture as compared to Process/thread-based
It can server max concurrent connections 10,000.

The Event Loop takes multiple requests without waiting.
Worker Processes prepares/computes and sends it to the client when each is ready.

Master Process

Supervises worker lifecycle
Reloads configuration without downtime
Never blocks on I/O or client handling
Enter fullscreen mode Exit fullscreen mode

Worker Processes

Each runs an independent, single-threaded event loop
Handles connection acceptance, reading, writing, and multiplexing
Scales across CPU cores by running multiple workers.
Enter fullscreen mode Exit fullscreen mode

Here are few use cases which we will cover in later blogs.
Load Balancing
Reverse Proxy
Forward Proxy
Caching

Deep diving further into the nginx architecture, the main configuration file is at the /etc/nginx/nginx.conf

At a glance, an nginx.conf file is divided into four main sections:

Global settings
events block
http block
server block

**1.Global settings**
These settings define user permissions, worker processes,file location, compression, caching, and more.

**2.Events block**
This controls Nginx’s event model and the maximum number of simultaneous connections per worker.

**3.http block**
Contains HTTP directives for logging, timeouts, compression, MIME types, and includes for server blocks.

**4.server block**
Configures how Nginx responds to requests for specific domain names or IP addresses (virtual hosts).
Enter fullscreen mode Exit fullscreen mode

Here are some important configuration files.

/etc/nginx/nginx.conf Main configuration file
/etc/nginx/sites-available/ Store individual server block files
/etc/nginx/sites-enabled/ Symbolic links to enabled sites from sites-available
/etc/nginx/conf.d/ Additional configuration snippets (e.g., SSL, load balancing)
/var/www/... Default web content roots (Debian/Ubuntu)
/usr/share/nginx/html

I will further add the important and intermediate configurations as per the scenario so its easier for understanding.

Documents to refer:
https://nginx.org/en/docs/
https://notes.kodekloud.com
Enter fullscreen mode Exit fullscreen mode

P.S. This post is a part of DevOps Micro Internship by Pravin Mishra.

Top comments (0)