Caddy reverse proxy to another domain

It happened to me with https, not sure if solution apply to websockets.

Front end caddy:

stg.example.com {
	reverse_proxy * https://int.example.com
}

Somehow the proxy connection complaint the backend is not stg and end up with empty reply. debug didn’t anything in my case. I enabled logging at site level on both front and back end caddy:

stg.example.com {
	log {
		format json
		output stdout
	}
	reverse_proxy * https://int.example.com

I did some cert trick to get it going during that time. But now there is a proper solution in the doc page example reverse_proxy (Caddyfile directive) — Caddy Documentation

stg.example.com {
	reverse_proxy * https://int.example.com  {
		header_up Host {http.reverse_proxy.upstream.hostport}
	}
}

header_up Host {http.reverse_proxy.upstream.hostport} replace the request header from front end to back end.

3 Likes