[Docker] Reverse-proxy in path for a React containerized app

FYI, you can simplify this:

     - "./config/Caddyfile:/etc/caddy/Caddyfile:ro"

This will set the Host header to client. Are you sure that’s what you want to do? That doesn’t make too much sense. You can probably remove both these header_up lines.

You can remove this too, Caddy passes through X-Forwarded-For already.

Your backend needs to be aware of the subpaths you’re trying to route with. See this article which explains in more detail:

You can probably only put the backend/API in a subpath, and let the frontend stuff sit at the root (i.e. all other requests). It would look like this:

localhost {
	handle_path /backend* {
		reverse_proxy server:8000
	}

	handle {
		reverse_proxy http://client:8888
	}
}

Using a handle with no matcher will make it act as a fallback, when no other handle block matched.

3 Likes