DEV Community

Cover image for Thoughts on :Nginx
Sunish Surendran K
Sunish Surendran K

Posted on

Thoughts on :Nginx

Fantastic way to wrangle some good software product is to experience it firsthand.So lets try Nginx today.And i have a weired hobby of connecting my fav software products with comic characters.

I have choosen Green Latern as Nginx
"All the powers that the Power Ring gives"

Image description

Nginx [engine x] is a free and opensource high performance web-server that can be used as

  • Reverse proxy
  • Load balancer
  • SMTP proxy
  • TCP/UDP proxy server.

There is a commercial edition available for Nginx called as Nginx Plus.

Source Code:

Image description

Nginx source code is published on mercurial , May be its new info for your, Mercurial is a free multiplatform distributed version control system. Mercurial is used via the command line; the program file itself is called hg.So like git we can download the nginx code using below command line.

hg clone

If you want to build the nginx from the source code please follow the link

NGINX Configuration file

Image description
NGINX can be configured with nginx.conf file, By default this file is named as nginx.conf and placed under /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.

The Nginx configuration file consist of Directives and Contexts

What are Directives and Contexts?

NGINX configuration consists of key-value pairs called directives. Directives decides which configuration to apply.They can be organized and grouped into Blocks known as Contexts.

Contexts are tree like structures that can be nested within one another and Directives can only been used within Contexts.

Directives and Context looks like below:
Image description

Nginx Architecture

Image description
Nginx has one master process and several worker processes.

The main purpose of the master process is to read and evaluate configuration, and maintain worker processes.

Worker processes do actual processing of requests. nginx employs event-based model and OS-dependent mechanisms to efficiently distribute requests among worker processes.

The number of worker processes is defined in the configuration file and may be fixed for a given configuration.

Image description
IF we mention auto like below the number of worker processes automatically adjusted to the number of available CPU cores
Image description

Each worker process can open a by default 512 connections

As previously mentioned, nginx doesn't spawn a process or thread for every connection. Instead, worker processes accept new requests from a shared "listen" socket and execute a highly efficient run-loop inside each worker to process thousands of connections per worker

Extending Nginx:

Nginx can be extended by using thrid-party modules.There is a large ecosystem of third‑party modules, ranging from language interpreters to security solutions.

Have a look at the below nginx blog about compling dynamic modules for nginx

Top comments (0)