On the same nginx/apache server:<ul><li>Scene 1: a.test.com and b.test.com can use keep-alive?</li> <li>Scene 2: localhost and 127.0.0.1 can use keep-alive?</li> </ul>
or the "Host header" must be consistent and the keep-alive will effective?Answer1:
For Apache it looks like it's based on IP address rather than host header, though I guess it also very much depends on client implementation.
<a href="https://httpd.apache.org/docs/2.4/vhosts/details.html#hostmatching" rel="nofollow">https://httpd.apache.org/docs/2.4/vhosts/details.html#hostmatching</a><blockquote>
The IP lookup described above is only done once for a particular TCP/IP session while the name lookup is done on every request during a KeepAlive/persistent connection. In other words, a client may request pages from different name-based vhosts during a single persistent connection.</blockquote>
Unless you are using tens of hundreds of domains I'd say you'd struggle to notice either way though it should be easy enough to test using developer tools or webpagetest.org to see if time is spent negotiating a new connection.