How to get ngrok working with dockerised caddy

Hi :slight_smile:

Sorry for the late response.

ngrok does not change the Host: header by default.
See ngrok Secure Tunnels | ngrok Documentation

So when you open the by ngrok provided domain, e.g. https://example.eu.ngrok.io/, then ngrok will just pass Host: example.eu.ngrok.io to Caddy.
And Caddy uses that to decide which vhost you are trying to reach (in your case fe.mnr.localhost or be.mnr.localhost).
But example.eu.ngrok.io won’t match for them, so Caddy is like “nah, I don’t know that one, sorry”.

So you would have to use

ngrok http --host-header=rewrite https://fe.mnr.localhost

and if you want to proxy be.mnr.localhost at the same time, then you need another instance via

ngrok http --host-header=rewrite https://be.mnr.localhost

Note: You might run into your ngrok plans’ rate limits

But also note, that I replaced http:// with https://.
That is because Caddy serves all vhosts via https by default. That’s called Automatic HTTPS — Caddy Documentation.
ngrok mentions that briefly in their docs at ngrok Secure Tunnels | ngrok Documentation

3 Likes