Sunday, August 23, 2015

virtualhost - When several name-based virtual hosts on the same web server share the same IP, do they necessarily share the same port?



https://en.wikipedia.org/wiki/Virtual_hosting




Name-based virtual hosts use multiple host names for the same IP
address.




A technical prerequisite needed for name-based virtual hosts is a web
browser with HTTP/1.1 support (commonplace today) to include the
target hostname in the request. This allows a server hosting multiple
sites behind one IP address to deliver the correct site's content.
More specifically it means setting the Host HTTP header, which is
mandatory in HTTP/1.1.[2]



For instance, a server could be receiving requests for two domains,
www.example.com and www.example.net, both of which resolve to the same
IP address. For www.example.com, the server would send the HTML file

from the directory /var/www/user/Joe/site/, while requests for
www.example.net would make the server serve pages from
/var/www/user/Mary/site/. Equally two subdomains of the same domain
may be hosted together. For instance, a blog server may host both
blog1.example.com and blog2.example.com.




When several name-based virtual hosts on the same web server share the same IP, do they necessarily share the same port?



Thanks.



Answer



No, the port number is completely separate. Think of the hostname/IP address as an office's main telephone number, and the port number as the extension you dial after you're connected to the main number. You can have multiple different server processes listening on the same IP address, each on a different port number, just like there would be multiple employees at the company each answering their own extension.



To take this metaphor even further, each of those employees would answer the phone identifying themselves with a different company name depending on which company you said you were calling (i.e. which of the multiple virtual hostnames you used to connect). This actually happens with answering services, they can see the number that you dialed before they answer, and when they pick up the phone they answer with the name of the firm that owns that number.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...