I am using the ask directive of on_demand_tls. If a particular domain doesn’t exist, right now it shows “url sent an invalid response, ERR_SSL_PROTOCOL_ERROR”. Is there a way to show a html page instead of this?
That’s impossible. If the TLS handshake fails, the client can’t trust anything coming from the server, so you’ll only ever be able to see the browser’s own error messages.
And to be clear, this is just how the Web works – not a limitation of Caddy, per-se. Browsers won’t even establish a secure connection without a valid certificate, so there’s no way to send an HTML response back.