Caddy

Caddy is a powerful, extensible platform to serve your sites, services, and apps, written in Go. If you’re new to Caddy, the way you serve the Web is about to change.

Regularly Used Commands

  • caddy run
    • start caddy server (may load the Caddyfile in cwd)
    • caddy run --config /path/to/Caddyfile
    • caddy run --watch watch config file changes
  • caddy start - start caddy server and have it run in the background
  • caddy stop - stop the caddy process
  • caddy reload - for a graceful config change
  • caddy adapt - convert Caddyfile to json structure

The Caddyfile

With Compression

1
2
3
4
5
localhost

encode zstd gzip
templates
file_server browse

Multiple Sites

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
:8080 {
respond "I am 8080"
}

:8081 {
respond "I am 8081"
}
:8082, :8083 {
  respond "I am 808*"
}

Reverse Proxy

1
2
3
4
localhost

file_server
reverse_proxy /api/* 127.0.0.1:9005

Environment Variables

1
export SITE_ADDRESS=localhost:9055
1
2
3
4
5
{$SITE_ADDRESS}

# also comments here

file_server

Static Files

  • caddy file-server --listen :2015
  • caddy file-server --browse - display a file listing (without index)
  • caddy file-server --root ~/site - use specific folder as site root

References

Get Things Done
Built with Hugo
Theme Stack designed by Jimmy