Nginx For Beginners

Introduction

Web Servers

A web server combines hardware and software to process client requests and serve web content—HTML, CSS, JavaScript, images, and more—back to your browser.

The image illustrates a web server concept with an icon of a server and a browser window, accompanied by a brief description of web servers.

How a Browser Loads a Web Page

When you type a URL (for example, KodeKloud.com) into your browser:

  1. The browser queries the DNS (Domain Name System) to resolve the domain name into an IP address.
  2. After obtaining the IP, it establishes a TCP connection to the server.
  3. The server receives the HTTP/HTTPS request, gathers the requested assets, and sends a response back.
  4. Your browser renders the response, displaying the web page.

The image is a flowchart illustrating the query process of accessing a website, from typing the website name to displaying the website.

Note

Think of DNS like a phone book—translating human-friendly domain names into machine-friendly IP addresses.

HTTP vs. HTTPS

Web servers communicate over two main protocols:

Most browsers redirect HTTP requests to HTTPS to protect data in transit.

The image shows two browser window illustrations with URLs, one using "https" and the other "http," highlighting the difference in protocols.

Warning

Transmitting sensitive information over plain HTTP can expose data to eavesdropping and man-in-the-middle attacks. Always prefer HTTPS.

Traditional vs. Modern Server Architectures

Legacy Servers: Apache & IIS

  • Apache HTTP Server (⟶ mid-1990s) uses a process-per-connection or thread-per-connection model.
  • Microsoft IIS launched around the same time with a similar architecture for Windows environments.

The image shows logos for traditional web servers: Apache and Microsoft Internet Information Services (IIS).

Spawning new processes for each request leads to increased CPU and memory usage under high load:

The image illustrates a web server handling multiple HTTP requests from "www.google.com," with a server showing 80% usage of both memory and CPU.

Modern Alternatives

Today's high-traffic sites distribute requests across clusters of servers behind load balancers. Popular event-driven and asynchronous servers include:

Web ServerFirst ReleasedConcurrency ModelKey Benefit
Nginx2004Event-driven, asyncLow memory footprint, high concurrency
OpenResty2011Nginx + Lua modulesExtensible with Lua scripting
LiteSpeed2003Event-drivenDrop-in Apache replacement option
Caddy2015Event-driven, GoAutomatic HTTPS distribution

The image lists commonly used web servers: Nginx, OpenResty, Litespeed, and Caddy, each with their respective logos.

In this guide, we'll focus on Nginx, exploring its architecture, configuration syntax, performance optimizations, and real-world deployment patterns.

References

Watch Video

Watch video content

Previous
Introduction and Objectives