Serve Static Files with Caddy: Minimal Setup Guide



This content originally appeared on DEV Community and was authored by Athreya aka Maneshwar

Hi there! I’m Maneshwar. Right now, I’m building LiveAPI, a first-of-its-kind tool that helps you automatically index API endpoints across all your repositories. LiveAPI makes it easier to discover, understand, and interact with APIs in large infrastructures.

Caddy is a lightweight, modern web server with automatic HTTPS, easy config, and a powerful plugin ecosystem. Here’s how to quickly serve static files with it.

1. Install Caddy

On Debian/Ubuntu:

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

2. Create Your Static Site Directory

mkdir -p /var/www/mysite
cd /var/www/mysite
echo "Hello from Caddy!" > index.html

You can place any static files here (HTML, CSS, JS, images, etc.).

3. Write the Caddyfile

Create a file named Caddyfile (default location: /etc/caddy/Caddyfile)

:80 {
    root * /var/www/mysite
    file_server
}

Explanation:

  • :80 → Serve on HTTP port 80 (use yourdomain.com for HTTPS).
  • root * /var/www/mysite → Set the root directory.
  • file_server → Enable static file serving.

4. Reload Caddy

After saving the Caddyfile:

sudo systemctl reload caddy

Or if running manually:

caddy run --config /etc/caddy/Caddyfile

5. Test It

Visit:

http://localhost/

You should see: Hello from Caddy!

Bonus: Enable HTTPS with a Domain

Update your Caddyfile:

yourdomain.com {
    root * /var/www/mysite
    file_server
}

Caddy will automatically fetch and renew the SSL cert via Let’s Encrypt.

Make sure port 80 and 443 are open, and DNS is correctly set.

Optional: Directory Browsing

:80 {
    root * /var/www/mysite
    file_server browse
}

Permissions

Make sure the Caddy user can read the static files:

sudo chown -R www-data:www-data /var/www/mysite

Run Caddy Without Systemd (Manual Dev Mode)

caddy file-server --root /var/www/mysite --listen :8080

That’s it. Static hosting done right with minimal config.
Use it to serve SPAs, HTML dumps, or just quick previews.

LiveAPI helps you get all your backend APIs documented in a few minutes.

With LiveAPI, you can generate interactive API docs that allow users to search and execute endpoints directly from the browser.

LiveAPI Demo

If you’re tired of updating Swagger manually or syncing Postman collections, give it a shot.


This content originally appeared on DEV Community and was authored by Athreya aka Maneshwar