📘 Visual Posts About Contact
Explore 📋 Cheat Sheets ✏️ Practice 🎮 Games 🎬 Simulations 🃏 Flashcards 🎯 Interactive Layers 📖 Storytelling
💜 Support my site

Request Routing: Web Servers & Proxies

Module 09 A–Z Server Course 2026 Updated

When you type a URL and press Enter, who answers the door? Learn how Web Servers (Nginx, Apache, IIS) serve files, host 10 websites on one IP, act as a Reverse Proxy shield, and lock traffic with HTTPS.

Start Module 09 ↓
REQUEST ROUTING & TLS TERMINATION Browser HTTPS :443 🔒 Encrypted Host: app.io TLS Reverse Proxy Nginx / Caddy / IIS 1. SSL Termination 2. Host Routing 3. Cache & Balance Static Files HTML, CSS, PNG App Node 1 127.0.0.1:3000 App Node 2 127.0.0.1:3001 Public Internet (Untrusted) ──▶ Private Loopback (Protected)

01 How a Web Server Works

Define: What is a Web Server?

A Web Server is a piece of software running on a computer that listens on network ports (usually TCP 80 for HTTP and TCP 443 for HTTPS), waits for incoming requests from browsers, and sends back a response — either a ready-made file or output from an application.

Understand: The Post Office & Menu Analogy

Imagine ordering food from a restaurant by phone:

  • DNS Lookup is looking up the restaurant's phone number in your contacts (turning shop.example.com into 203.0.113.10).
  • TCP Connection (Port 80/443) is dialing the front desk and hearing "Hello, how can I help you?"
  • Static Files (HTML, CSS, images, PDFs) are pre-packaged snacks sitting on the counter — the receptionist hands them to you immediately.
  • App Server (Node.js, Python, PHP, .NET) is the kitchen — when you ask for your live bank balance or shopping cart, the receptionist passes the ticket to the kitchen to cook up a fresh response.
STEP BY STEP: FROM URL BAR TO SCREEN 1. Browser GET /index.html User types URL in address bar 2. DNS Lookup example.com → 203.0.113.10 3. TCP Connect Port 80 (HTTP) Port 443 (HTTPS) 4. Web Server Nginx / Apache / IIS Reads HTTP path & decides route Static Disk Files /var/www/html/ Fast! No code needed Dynamic App Server Node / Python / .NET Runs logic + Database

Know & When: Static vs. Dynamic

Web servers excel at reading files from disk and streaming them over the network at blistering speed. Application servers (like Gunicorn, Node.js, or ASP.NET Core) excel at running business logic and querying databases. In production, you almost always put a web server in front of your app server.

🧠 Memory Trick: Port 80 vs Port 443

80 is Plain (HTTP — open postcard anyone can read), 443 is Fortress (HTTPS — 4-4-3 has three digits like a 3-dial padlock). Never leave production logins on Port 80!

Execute: Check What is Listening on 80 & 443

# Linux: see which process owns ports 80 and 443
sudo ss -tulpn | grep -E ':80|:443'

# Windows PowerShell: see which PID owns ports 80 and 443
Get-NetTCPConnection -LocalPort 80,443 -State Listen

02 Nginx vs Apache vs Windows IIS

Define: The Big Three Web Servers

Almost every website on the internet is served by one of three engines: Nginx (pronounced "Engine-X"), Apache HTTP Server, or Microsoft IIS (Internet Information Services).

Understand: Receptionist vs Dedicated Waiters

Why does Nginx handle 10,000+ simultaneous visitors on tiny RAM while classic Apache struggles? It comes down to how they handle connections:

  • Nginx (Event-Driven Receptionist): One super-fast receptionist sits at the front desk with an event loop. When Visitor A is waiting for a slow database, the receptionist doesn't freeze — they immediately greet Visitors B, C, and D, and hand A their food the instant it's ready.
  • Apache (Dedicated Waiters — Process/Thread): Classic Apache assigns a dedicated waiter (process or thread) to each table. While the customer reads the menu, that waiter stands idle, holding RAM. Great for compatibility and .htaccess, heavier under massive concurrency.
  • Windows IIS (Kernel-Integrated Kitchen): Built right into Windows Server with http.sys in the kernel, managed via GUI or PowerShell, and deeply integrated with Active Directory and ASP.NET.
CONCURRENCY MODEL: EVENT-DRIVEN VS PROCESS/THREAD NGINX (Event-Driven) 1 Worker = Thousands of Connections Req 1 Req 2 Req 3 Req 4 ...10,000+ Event Loop Non-blocking Low RAM usage APACHE / IIS (Waiter per Table) 1 Connection = 1 Process or Thread Req 1 Worker Thread 1 (RAM) Req 2 Worker Thread 2 (RAM) Req 3 Worker Thread 3 (RAM)

Know: Side-by-Side Comparison

Feature Nginx Apache HTTP Server Windows IIS
OS Support Linux, BSD, Windows Linux, BSD, Windows Windows Server only
Architecture Event-driven, async Process / Thread (MPM) Kernel http.sys + Worker Pools
Per-Folder Config No (centralized config = faster) Yes (.htaccess) Yes (web.config)
Best Use Case Reverse proxy, static files, high traffic Shared hosting, legacy PHP / WordPress Enterprise .NET, Active Directory SSO

When & Execute

Choose Nginx (or modern Caddy) for reverse proxies, containers, and high-concurrency APIs. Choose Apache if you need per-directory .htaccess rules on shared hosting. Choose IIS when your company runs Windows Server and ASP.NET.

✅ Checkpoint: Sections 01–02

  • Web servers listen on TCP 80 (HTTP) and TCP 443 (HTTPS).
  • Static files are served straight from disk; dynamic requests go to an App Server.
  • Nginx uses an event-driven receptionist model, keeping memory usage tiny at high scale.

03 Virtual Hosts & Server Blocks

Define: What is a Virtual Host?

A Virtual Host (called a Server Block in Nginx, VirtualHost in Apache, and Site Binding in IIS) lets a single server with one public IP address host 10, 50, or 500 completely different websites.

Understand: The Apartment Building Mailbox Analogy

Think of your server's IP address (203.0.113.10) as the street address of an apartment building. All mail arrives at the same front door. How does the building manager know which apartment gets the letter? They read the name on the envelope!

In HTTP, every browser automatically puts an envelope label inside the request called the Host: header (for example, Host: shop.example.com). The web server reads that header and routes the request to the matching folder or backend app.

1 PUBLIC IP (203.0.113.10) → MANY WEBSITES VIA HOST HEADER Visitor 1 Host: shop.site.com Visitor 2 Host: blog.site.com Visitor 3 Host: api.site.com Nginx Server IP: 203.0.113.10 Port: 443 Matches server_name shop.site.com blog.site.com api.site.com Block 1: Storefront /var/www/shop/ Block 2: Blog /var/www/blog/ Block 3: API Backend proxy → 127.0.0.1:8080

Know & Execute: Nginx Server Block Example

In Ubuntu/Debian Nginx, each website gets its own file in /etc/nginx/sites-available/, then you enable it with a symlink into /etc/nginx/sites-enabled/:

server {
    listen 80;
    server_name shop.site.com www.shop.site.com;

    root /var/www/shop;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

✏️ Practice Problem: Missing Host Header

You configure two Nginx server blocks: alpha.com and beta.com on the same IP 203.0.113.10. A user types http://203.0.113.10 directly into their browser instead of a domain name. Which site will Nginx serve?

Show Solution

Nginx will serve whichever server block has default_server on listen 80 default_server; — or if none is marked, the first server block loaded alphabetically. Best practice: always define an explicit catch-all default_server block that returns 444 or a neutral page so scanners hitting your raw IP don't accidentally see a tenant site.

04 Reverse Proxy & Load Balancing

Define: Forward Proxy vs Reverse Proxy

  • Forward Proxy sits in front of clients (e.g., an office VPN/proxy hiding employees' IPs from the internet).
  • Reverse Proxy sits in front of servers — clients think they are talking directly to your app, while the proxy quietly shields, caches, and distributes traffic behind the scenes.

Understand: The Nightclub Bouncer & Traffic Cop

A Reverse Proxy is your backend's bodyguard and dispatcher. It handles four critical jobs so your application code doesn't have to:

TLS

SSL Termination

The proxy decrypts heavy HTTPS traffic once at the front door, then forwards fast plain HTTP to internal backend apps on 127.0.0.1 or a private VPC.

LB

Load Balancing

Spreads incoming requests across multiple app instances (Round Robin, Least Connections, or IP Hash) so no single server melts down.

HC

Health Checks

If App Node 2 crashes or stops responding, the proxy marks it unhealthy and routes 100% of users to healthy nodes automatically.

⚡

Caching & Compression

Caches popular responses in RAM and compresses payloads with Gzip/Brotli before sending them over slow mobile networks.

REVERSE PROXY: SSL TERMINATION + LOAD BALANCING + HEALTH CHECK Clients 🔒 HTTPS :443 Thousands of browsers/apps Nginx Reverse Proxy SSL Termination (Decrypts) Cache Hit? Serve Instantly Upstream Pool + Health Check App Node 1 (Healthy ✓) 10.0.1.11:3000 — 50% traffic App Node 2 (Healthy ✓) 10.0.1.12:3000 — 50% traffic App Node 3 (Down ✗) 10.0.1.13:3000 — Bypassed X-Forwarded-For & X-Forwarded-Proto preserve real client IP

Execute: Nginx Upstream Load Balancer Config

upstream app_cluster {
    server 10.0.1.11:3000 max_fails=3 fail_timeout=30s;
    server 10.0.1.12:3000 max_fails=3 fail_timeout=30s;
}

server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://app_cluster;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
⚠️ Don't Forget Proxy Headers! Without X-Real-IP and X-Forwarded-For, your backend app logs will show every single visitor as coming from 127.0.0.1 (the proxy itself)!

05 SSL/TLS & Let's Encrypt HTTPS

Define: What is HTTPS & TLS?

HTTPS is HTTP wrapped inside TLS (Transport Layer Security — the modern replacement for SSL). It guarantees three things: Encryption (nobody on public Wi-Fi can read your data), Integrity (nobody can tamper with it), and Authentication (you are talking to the real server, not an impostor).

Understand: How the Browser Padlock Works

How does your browser trust a server it has never met before? Through a Certificate Authority (CA) — a trusted passport issuer like Let's Encrypt. When the browser connects on Port 443, the server presents its signed digital passport (TLS Certificate). The browser verifies the signature, agrees on a shared secret session key via the TLS Handshake, and locks the tunnel.

TLS HANDSHAKE & LET'S ENCRYPT AUTOMATION Browser Web Server Let's Encrypt CA Certbot ACME Challenge (90d Free) Signed TLS Cert + Key 1. ClientHello (TLS 1.3) 2. ServerHello + Cert 🔒 3. Encrypted HTTPS Tunnel Active

Know & Execute: Practical Certbot & nginx -t Workflow

In 2026, you never buy basic TLS certificates manually — Certbot (or Caddy's built-in ACME) fetches and auto-renews free 90-day Let's Encrypt certificates. Always test your config syntax with nginx -t before reloading!

# 1. Obtain & auto-configure a free Let's Encrypt HTTPS certificate
sudo certbot --nginx -d app.example.com

# 2. ALWAYS test Nginx syntax before applying (prevents downtime!)
sudo nginx -t
# Output: nginx: configuration file /etc/nginx/nginx.conf test is successful

# 3. Reload gracefully without dropping active user connections
sudo systemctl reload nginx

🧠 Memory Trick: Test Before Reload!

Remember nginx -t = Test, Then Trigger. Never run systemctl restart nginx blindly on a live server — a single missing semicolon (;) will take every site offline. nginx -t catches syntax errors first, and reload applies changes with zero dropped connections.

✏️ Practice Problem: Broken Config Recovery

You edit /etc/nginx/sites-available/api.conf and run sudo nginx -t. It reports: nginx: [emerg] unexpected "}" in /etc/nginx/sites-available/api.conf:14. What should you do next, and are live users currently affected?

Show Solution

Live users are NOT affected yet! Because you ran nginx -t instead of restarting, the old working configuration is still running in memory. Fix the missing semicolon (;) on line 13 (just before the closing } on line 14), re-run sudo nginx -t until it says test is successful, and then run sudo systemctl reload nginx.

🎯 Knowledge Check

Test your Module 09 Request Routing mastery: Score: 0 / 4

1. Why can Nginx handle thousands of concurrent connections using far less RAM than classic process-per-connection servers?

A) It uses an asynchronous, event-driven loop (receptionist model)
B) It skips TCP connections and uses UDP only
C) It spawns a dedicated OS process for every single browser tab

2. How does a single web server with one IP address know whether to serve shop.site.com or blog.site.com?

A) It assigns a different public TCP port to each website
B) It reads the HTTP Host header (and TLS SNI) in the incoming request
C) It asks the user to click a folder from a directory list

3. What does "SSL Termination" at a Reverse Proxy mean?

A) Disabling HTTPS completely so all internet traffic is unencrypted
B) The proxy decrypts HTTPS traffic at the edge before forwarding to internal backends
C) Deleting expired TLS certificates from the server

4. Which command safely verifies your Nginx configuration syntax before applying changes to a live server?

A) sudo nginx -t
B) sudo systemctl restart nginx
C) sudo certbot --verify