There are various articles and questions explaining how to use a given reverse proxy's (e.g. nginx) implementation of this [1] [2] [3] [4], but none explain how this actually works under the hood.
By "TLS Passthrough based on SNI", I am referring to a proxy that does not perform TLS termination at the proxy, but forwards the unencrypted TLS packets directly to the upstream server, based on the SNI in the TLS clientHello packet.
Could someone explain how this works in detail?
- For example, I assume a TCP handshake between the client and proxy is performed first, and from the TLS clientHello onwards, the correct upstream server is selected, and the proxy thus acts as a L4 reverse proxy; but does the proxy establish a separate TCP handshake between itself and the server before forwarding the clientHello? What goes on after that?
- Also, what happens when multiple domains share the same IP, how does the proxy distinguish between flows to each of these domains, given that the SNI only appears in the clientHello?