It is my understanding that when Apache receives a request to one of the TCP ports it is listening on (e.g. 80, 443), it will decide which host is being requested by looking at the HTTP header Host
. The server will then know which virtual host it should redirect the request to.
But how does it work for HTTP over SSL/TLS? Since the whole HTTP request is being encrypted (at least that's what I believe I have read somewhere), the header information can only be read after the server has decrypted the data. But in order to decrypt, it needs to know which key pair to use as you can have multiple SSL certificates installed on a web server.
So how does the server know which key it needs for decryption?
My guess:
I could imagine that the TLS handshake provides the necessary information.
Regarding the "possible duplicate" flag:
While I agree that the answers to both the linked question and my own are similar, I must say the question is different. It is out of question whether or how hosting multiple sites with independet SSL certificates is possible. Instead my question addresses the underlying technical aspect.