Nginx Explained

What is Nginx?

Nginx is pronounced as "Engine-X" (I used to say it as n-jinx before πŸ˜‚) is a high-performance proxy web server, which handles HTTP requests.

Now what do I mean by that? 🀨

Typically when you make a browser request, the data is fetched from the web servers and the output is shown on the browser, but that’s not just it.

There exists a proxy server between your browser requests and the web server which has a handful of useful core features.

Features of a Proxy Server πŸ–₯️

  1. It acts as Load Balancer.

  2. It has Caching functionality.

  3. Provides security.

  4. Compression and Segmentation of files.

Load Balancing βš–οΈ

The proxy server Nginx distributes the incoming traffic coming from the user’s browser requests across multiple backend servers. It balances load, improves performance and provides redundancy.

The Load Balancing mostly includes 2 types of methods:

  1. Least Connections - The backend server with the least load among others gets the requests to fetch the data.

  2. Round-Robin - By default, NGINX uses a round-robin method for load balancing It’s a scheduling technique that distributes tasks or requests evenly across a group of servers or processors, by cycling through them one at a time.

Caching πŸ«™

Caching is another essential feature of the Nginx Proxy server. This functionality involves temporarily storing frequently accessed resources or files within the proxy server itself. By doing so, it significantly enhances performance by reducing the time it takes to retrieve these resources from the original web server.

a pixelated image of a man wearing headphones with the word cache on the bottom

When a user requests a resource that has been cached, the proxy server can deliver it directly, bypassing the need to fetch it from the backend server again. This not only speeds up the response time for users but also reduces the load on the backend servers, allowing them to handle more requests efficiently.

Security πŸ”’

Nginx serves as a single entry point to multiple servers. This setup enhances security by consolidating it, minimizing public exposure, and centralizing logging and monitoring.

It basically acts like a shield to protect the backend servers from compromising themselves.

captain america is holding a shield while fighting wolverine in a cartoon .

Nginx manages SSL encryption and decryption. If an attacker intercepts the messages, they won't be able to read or understand them. Nginx only accepts encrypted traffic and blocks any non-encrypted requests.

Compression & Segmentation πŸ—œοΈ

This proxy server can also compress images and videos to reduce the bandwidth usage and improve load times. It also sends files in segmentations or chunks and not all at once to maintain speed and efficiency.

The popular streaming company Netflix uses Nginx as it’s proxy server, How?

a row of colorful striped lines on a black background

When you're tired after a long day and want to Netflix and chill🌚, you select a movie or series and send a data request. This request travels as encrypted traffic to the Nginx proxy server. The server balances the load, fetches the data from the web server, and sends it back to you. The proxy server compresses and segments the movie or series, sending the compressed data in chunks, one by one.

How to configure Nginx ? πŸ€”

The main config file is typically named nginx.config and is usually located in /etc/nginx/ folder.

It uses custom syntax, comprising of Directives and Blocks.

This config file sets up the server behavior along with configuring custom load balancing method. We can specify if the Nginx should be a web server or handle requests itself.

Note: Communicating on port 80 or HTTP is insecure, make sure to encrypt it by creating a directive to convert HTTP to HTTPS with SSL.

You can also configure caching by setting the time period or the temporary storage duration for cached files.

Seafile In Docker - Trigger Nginx Config Regeneration - Seafile Server -  Seafile Community Forum

Ingress Controller πŸŽ›οΈ

What's Ingress? It refers to incoming traffic. An Ingress controller is a specialized load balancer used to manage incoming traffic in Kubernetes.

It handles the routing to the appropriate services based on the rules defined in the ingress resources.

Nginx is the most popular Ingress controller used in Kubernetes.

Cloud Load Balancers πŸ†š Nginx

The Nginx Ingress Controller acts as a load balancer inside the Kubernetes cluster. It is not publicly accessible.

Whereas the Cloud LB handles the incoming traffic from the internet, forwards it to Nginx. This way the Kubernetes cluster is not exposed. Nginx also has intelligent routing, It forwards specific requests to the relevant servers.

Examples of Cloud Load Balancers are AWS CLB, Google CLB, Azure CLB, IBM LB etc.

Apache πŸ†š Nginx

  • Both are proxy servers.

  • Apache was released in 1995 & Nginx in 2004.

  • Apache is almost as same as Nginx but, Nginx is lighter and faster.

  • Apache is a good choice for dynamic content and handling legacy support.

  • Nginx is best suited for high-performance environment an serving static content. It also has simple configuration.

  • Nginx is more popular in the container world.

Conclusion πŸ˜„

In short, NGINX is like the high-speed traffic cop of the web. It’s fast, lean, and handles HTTP requests, load balancing, SSL encryption, and security like a pro. 😎Whether optimizing traffic across servers or being a powerful ingress controller in Kubernetes, NGINX keeps things smooth, secure, and efficient. While Apache tries its best, NGINX brings the speed and sass to high-performance environments.

11
Subscribe to my newsletter

Read articles from Shah Abul Kalam A K directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shah Abul Kalam A K
Shah Abul Kalam A K

Hi, my name is Shah and I'm learning my way through various fascinating technologies.