Nginx
Nginx is still the most common way to self-host a static site, and it is fast and frugal at it. It also has a few configuration traps that matter more for static sites than anything else: add_header directives that silently stop applying in nested locations, try_files patterns copied from single-page apps that turn every missing page into a soft 404, and on-the-fly compression doing work a build could do once.
The guides below cover a production configuration end to end: caching headers per file type, precompressed Brotli and gzip served with the static modules, a small unprivileged container image for container platforms, and a measured comparison with Caddy for teams deciding between the two.
Core Web Vitals Optimization for SSGs
- Cache-Control Headers for Static Sites in NginxHow-toSet Cache-Control in Nginx for a static site: immutable hashed assets, revalidated HTML, short-lived 404s and the add_header inheritance trap.
- Precompressing Assets with Brotli and ZstdHow-toPrecompress static site output at build time with brotli 11 and zstd 19, serve the variants from Caddy, nginx or Cloudflare, and measure the transfer saving.
Production-Ready Deployment & CI/CD for SSGs
- Nginx vs Caddy for Serving Static SitesComparisonNginx and Caddy compared serving the same static site: throughput, latency, memory, TLS automation, config size, compression and the mistakes each one invites.
- Brotli and Gzip Precompression Served by NginxHow-toServe build-time Brotli and gzip files from Nginx with brotli_static and gzip_static, verify negotiation and Vary headers, and measure bytes and CPU saved.
- Serving a Static Site From a Docker Container With NginxHow-toPackage a static site in a small Nginx container: multi-stage build, non-root user, read-only filesystem, health checks and running behind a proxy.
- Serving a Static Site with CaddyHow-toHost a static site on Caddy with automatic HTTPS, clean URLs, precompressed files, cache tiers, security headers and per-pull-request preview subdomains.
- Serving a Static Site with NginxHow-toA production nginx config for a static site: clean URLs, two cache tiers, brotli, security headers that survive nested blocks, redirects, TLS and the 404 page.
Often used with nginx
- Caddy3 shared guidesSelf-hosted serving with automatic HTTPS.
- Eleventy1 shared guidesIncremental builds, image pipelines and the data cascade.
- Cloudflare1 shared guidesPages and Workers hosting, cache rules and edge functions.