How Web Servers Serve Traffic
Understand what a web server does in front of an application: static files, virtual hosts, TLS termination, proxying, caching and logging.
Beginner · about 3 hours · difficulty 2/5
Learn first: HTTP and HTTPS, Load Balancing and Proxies
Application runtimes like Node, Gunicorn or a Java server are rarely exposed to the internet directly. A web server or reverse proxy sits in front and handles the jobs it is better at.
Responsibilities
- Static content: serving files efficiently with correct caching headers and compression.
- Virtual hosts: many sites on one server, selected by the
Hostheader or SNI. - TLS termination: decrypt once at the edge, then forward plain HTTP or re-encrypt.
- Reverse proxying to upstream app servers, with timeouts, buffering and retries.
- Protection: rate limits, request size limits, basic auth, IP allow lists, security headers.
- Access and error logs in a format your log pipeline can parse (JSON is easiest).
Architecture choices
Event-driven servers (Nginx, Caddy, HAProxy) handle many connections with few threads; process-per-request models (classic Apache prefork) use more memory. In Kubernetes, these same servers appear as ingress controllers and sidecars.
Pitfalls
Default timeouts that are too short for uploads or too long for a failing backend, missing X-Forwarded-Proto so apps generate http:// links, and config changes applied without a syntax check (nginx -t).
Good enough to move on: you can describe each hop a request takes from browser to app and which component should own caching, TLS and rate limiting.
Key concepts
- Static vs dynamic content
- Virtual hosts
- TLS termination
- Upstreams and timeouts
- Compression and caching headers
- Security headers
- Structured access logs
Mini project
Sketch and document the request path for a site with a CDN, a load balancer, a web server and two app servers, noting where TLS ends, where logs are written and where caching happens.
Check yourself
Why does an app behind a TLS-terminating proxy sometimes redirect users to http:// URLs, and how do you fix it?
Free resources
- MDN: HTTP caching (MDN)
- What is a reverse proxy? (Cloudflare)