Ravindra BagaleCourses & study guides

Chapter 6: Web Servers — Nginx and Apache

6.1 What is a web server?

Mitranno, till now we launched a server. But a server without a web server is like a shop with the shutter down — customers come but nobody serves them. Let's understand what a web server really does. A web server is software that listens on a port (80 for HTTP, 443 for HTTPS), accepts HTTP requests from browsers and returns responses — HTML pages, images, CSS, JavaScript files, or data produced by an application.

  Browser                         EC2 instance
 +--------+   GET /index.html    +---------------------------------------+
 |        | -------------------> | Web server (Nginx / Apache) :80       |
 |        |                      |   ├─ static file?  → read from disk   |
 |        | <------------------- |   └─ dynamic?      → pass to PHP /    |
 +--------+   200 OK + HTML      |                      Node / Python app|
                                 +---------------------------------------+

A web server does three main jobs:

  1. Serve static content — files that are the same for everyone (HTML, CSS, JS, images).
  2. Pass dynamic requests to an application (PHP-FPM, Node.js, Gunicorn) — called reverse proxying — and return its output.
  3. Handle cross-cutting concerns — TLS/HTTPS, compression, caching, logging, virtual hosts (many websites on one server), load balancing, rate limiting.

Common HTTP status codes

Code Meaning Typical cause
200 OK Success
301 / 302 Moved permanently / temporarily Redirect (e.g. HTTP → HTTPS)
304 Not modified Browser cache is fresh
400 Bad request Malformed request
401 / 403 Unauthorised / Forbidden Missing login / file permissions, no index file, SELinux
404 Not Found Wrong path or wrong document root
500 Internal server error Bug in app / PHP error
502 Bad Gateway Reverse-proxy target (app) is down or wrong port/socket
503 Service unavailable Overloaded or maintenance
504 Gateway timeout App took too long to respond