Home › Other › Web Servers

Web Servers

A web server answers HTTP requests. Modern setups layer a reverse proxy in front of your application to handle the hard parts.

A web server is a program that listens for HTTP requests and sends back responses — files, or output from your application. Common ones are Nginx, Apache, Caddy, and the dev servers built into frameworks.

Serving static files

The simplest job: map a URL to a file on disk and send it. A request for /about.html returns the file at /var/www/about.html. Fast, cacheable, and plenty for a static site.

The reverse proxy

For dynamic apps, you usually do not expose your application directly. Instead a web server sits in front as a reverse proxy, forwarding requests to your app running on an internal port:

Browser  ->  Caddy/Nginx (:443)  ->  your app (:3000)

The proxy handles the things your app should not have to:

A tiny Caddy config

example.com {
    root * /var/www
    file_server
    reverse_proxy /api/* localhost:3000
}

That serves files from a folder, proxies anything under /api/ to a local app, and — because it is Caddy — obtains and renews an HTTPS certificate automatically.

Load balancing

When one app instance is not enough, a load balancer (often the same reverse proxy) spreads requests across several, and stops sending traffic to any that fall over. That is the foundation of scaling a web service horizontally.

Forwarded headers: behind a proxy your app sees the proxy’s IP, not the visitor’s. The proxy adds X-Forwarded-For so the real client IP is still available — make sure your app reads it.

Keep reading