1. caddy
$ caddy
Caddy is an extensible server platform written in Go.

At its core, Caddy merely manages configuration. Modules are plugged
in statically at compile-time to provide useful functionality. Caddy's
standard distribution includes common modules to serve HTTP, TLS,
and PKI applications, including the automation of certificates.

To run Caddy, use:

        - 'caddy run' to run Caddy in the foreground (recommended).
        - 'caddy start' to start Caddy in the background; only do this
          if you will be keeping the terminal window open until you run
          'caddy stop' to close the server.
...
alexlai@orgpi516G ~/build/caddy-getting-started $ caddy run
2023/12/16 01:46:26.144 INFO    admin   admin endpoint started  {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/12/16 01:46:26.144 INFO    serving initial configuration
alexlai@orgpi516G ~/build/caddy-getting-started $ curl localhost:2019/config/
null
  1. Give Caddy a config, using json file format
{
	"apps": {
		"http": {
			"servers": {
				"example": {
					"listen": [":2015"],
					"routes": [
						{
							"handle": [{
								"handler": "static_response",
								"body": "Hello, world!"
							}]
						}
					]
				}
			}
		}
	}
}
curl localhost:2019/load \
	-H "Content-Type: application/json" \
	-d @caddy.json
$ curl localhost:2019/config/
{"apps":{"http":{"servers":{"example":{"listen":[":2015"],"routes":[{"handle":[{"body":"Hello, world!","handler":"static_response"}]}]}}}}}
$ curl localhost:2015
Hello, world!
  1. config file using Caddyfile

The above caddy.json, could be expressed in Caddyfile as,

:2015

respond "Hello, world! From YuShei!"
alexlai@orgpi516G ~/build/caddy-getting-started $ caddy run
2023/12/16 03:11:00.503 INFO    using adjacent Caddyfile
2023/12/16 03:11:00.508 INFO    admin   admin endpoint started  {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/12/16 03:11:00.508 INFO    http.log        server running  {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2023/12/16 03:11:00.508 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0x40001dc900"}
2023/12/16 03:11:00.508 INFO    autosaved config (load with --resume flag)      {"file": "/home/alexlai/.config/caddy/autosave.json"}
2023/12/16 03:11:00.509 INFO    serving initial configuration
2023/12/16 03:11:00.509 INFO    tls     cleaning storage unit   {"description": "FileStorage:/home/alexlai/.local/share/caddy"}
2023/12/16 03:11:00.510 INFO    tls     finished cleaning storage units
...
$ curl localhost:2015
Hello, world! From Yushei!
  1. Define Multiple Sites, as multiple.json
{
	"apps": {
		"http": {
			"servers": {
				"hello": {
					"listen": [":2015"],
					"routes": [
						{
							"handle": [{
								"handler": "static_response",
								"body": "Hello, world!"
							}]
						}
					]
				},
				"bye": {
					"listen": [":2016"],
					"routes": [
						{
							"handle": [{
								"handler": "static_response",
								"body": "Goodbye, world!"
							}]
						}
					]
				}
			}
		}
	}
}
curl localhost:2019/load \
	-H "Content-Type: application/json" \
	-d @multiple.json
alexlai@orgpi516G ~/build/caddy-getting-started $ curl localhost:2019/load \
        -H "Content-Type: application/json" \
        -d @multiple.json
alexlai@orgpi516G ~/build/caddy-getting-started $ curl localhost:2015
Hello, world!
alexlai@orgpi516G ~/build/caddy-getting-started $ curl localhost:2016
Goodbye, world!