How to use a reverse proxy to split traffic between containers based on URL

Solution 1:

No, there is nothing in TCP that would indicate which domain name (much less which URL) was originally requested; only the peers' IP addresses and TCP ports are known.

So this is only possible if you have a higher-layer protocol that provides the necessary information (much like HTTP does in its 'Host' header), and the proxy must understand that higher-layer protocol. Generic TCP multiplexing based on domain name is not possible.

For example, if all your services use TLS, then you could multiplex based on the domain name sent in the TLS SNI extension (and possibly even the protocol type sent in TLS ALPN) – this can be done using HAproxy, sniproxy, or possibly even Nginx.

(There are also specialized proxies which can multiplex different protocols based on the recognized client handshake – e.g. 'sshttp' can deal with SSH & HTTP on the same port, similarly 'sslh' does SSH & TLS. All such proxies need at least basic understanding of all protocols involved, and they only work reliably with protocols where the client speaks first.)