Is http keep-alive effective with different domain

2019-09-01 09:39发布

问题:

On the same nginx/apache server:

  • Scene 1: a.test.com and b.test.com can use keep-alive?
  • Scene 2: localhost and 127.0.0.1 can use keep-alive?

or the "Host header" must be consistent and the keep-alive will effective?

回答1:

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.

https://httpd.apache.org/docs/2.4/vhosts/details.html#hostmatching

Persistent connections

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.

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.