1. The problem I’m having:
I want to specify a default certificate which is used when the service asked by TLS on_demand feature returns a non HTTP 200 code (=says issuing certificates for this domain is prohibited).
2. Caddy version:
v2.7.4 h1:J8nisjdOxnYHXlorUKXY75Gr6iBfudfoGhrJ8t7/flI=
4. How I installed and ran Caddy:
I installed it manually and run it via systemd unit.
a. System environment:
Debian bookworm, amd64
b. Command:
/usr/local/bin/caddy run --environ --config /etc/caddy/Caddyfile
c. My complete Caddy config:
{
# Don't redirect everything to TLS to keep the number of issued
# certificates low
auto_https disable_redirects
on_demand_tls {
ask http://localhost:5555/
}
}
(default-redirector) {
log {
output file /var/log/caddy/redirector.log {
roll_size 1gb
roll_local_time
roll_keep 0
roll_keep_for 168h
}
}
@default_redirect {
method GET
}
route {
handle @default_redirect {
redir https://www.example.org/?utm_source={host}&utm_medium=referral&utm_campaign=redirector-service 302
}
# Every request hitting the following redirect is not doing
# a normal GET request. Therefore we are forcing
# HTTP status 303 to prevent redirect target from receiving
# unwated POST calls for example.
redir https://www.example.org/?utm_source={host}&utm_medium=referral&utm_campaign=redirector-service 303
}
}
:80 {
# Bind to specific IP because this host has multiple IP addresses
# and not every address should be used by caddy.
bind 203.0.113.2
import default-redirector
}
:443 {
# Bind to specific IP because this host has multiple IP addresses
# and not every address should be used by caddy.
bind 203.0.113.2
tls {
on_demand
}
import default-redirector
}
We have a big site example.org
and thousands of alias domains pointing to this site. A typical alias site’s DNS zone will look like
example.de. 300 IN A 203.0.113.2
*.example.de. 300 IN CNAME redirect.to.example.org.
The service running at http://localhost:5555
will verify that the domain specified is really pointing at us.
Due to wildcard usage the service is also blocking certain unwanted subdomains and ensures that we don’t allow undefined levels of subdomains. But these details shouldn’t matter.
Anyway, so whenever the checking service forbids Caddy to issue a certificate, Caddy is currently aborting the connection.
However, I want that Caddy will use a default certificate in that case and still do the redirect (yes I know that most clients will probably display a certificate error but that’s fine for me. It’s still giving users a hint and in case someone ignores the error, I want them to reach our main site). Or in other words the default behavior when I would use an Apache/nginx server, where I would set a default SSL vhost which would get used in this case.
Is that possible with Caddy in combination with TLS on_demand?
Second question I have: Can I get Caddy to query check service also for HTTP requests? Like we already have implemented a bunch of checks/logic into the check service to not redirect everything. It would be cool if we could re-use this logic also for HTTP calls.