Redirect subdomains to other public servers with caddy

1. The problem I’m having:

we have many subdomains and want to use a central Caddy server to redirect all requests to the subdomains to other caddy public servers. We are doing this in order to avoid creating thousands of DNS entries for each subdomain, instead we use a dns * wildcard that points to the main Caddy server

2. Error messages and/or full log output:

a.test.com {reverse_proxy https://12.123.12.244}
b.test.com {reverse_proxy https://12.123.12.244}
c.test.com {reverse_proxy https://12.123.12.244}

3. Caddy version:

v2.11.2

4. How I installed and ran Caddy:

installed on a Debian server

a. System environment:

Debian server

b. Command:

we have the main Caddy server that reverse_proxy to other Caddy servers with the same subdomains but configured as serving files with

a.test.com {
  root * /var/www/a.test.com
  file_server
}

c. Service/unit/compose file:


d. My complete Caddy config:

we have the main server with the following configuration

a.test.com {
	reverse_proxy https://12.123.12.244
}

and the receiving Caddy server at IP 12.123.12.244 configured like this:

a.test.com {
	root * /var/www/a.test.com
	file_server
}

another test

we tried to use the following on the main server:


a.test.com {
reverse_proxy 12.123.12.244:443
}


and we get the following error in the browser:

Client sent an HTTP request to an HTTPS server.
```

Please share the error log from the central Caddy server and the curl command tests you ran against it.