2.2. One server, multiple 'virtual' hosts

There are (at least) three different ways that a single web server, and a single copy of Apache, can host more than one web site. The important issue here is how Apache can work out which site is relevant for each request.

Multiple ports: A web server can listen on more than the default TCP port (number 80) and offer different web sites on each port. To identify a non-standard port, its number must follow the server name in the URL: http://www.dept.cam.ac.uk:port/some/path/here/. Apache uses the port number of the incoming query to distinguish between web sites. Beware that from some environments, particularly those behind firewalls or on wireless networks, it may be difficult or impossible to access web servers running on non-default ports.

Multiple addresses: A single system can have more than one IP address and each can have a different web site attached to it. This leads to different server names appearing in standard URLs (i.e. there's no :port element in the URL) but the server names correspond to different IP addresses of the system and correspond to different web sites. Apache uses the destination IP address on the incoming query to distinguish web sites. Nowadays this approach is not encouraged because IP addresses are in short supply.

Multiple aliases. Also known as name-based virtual hosting, this is the most common form of virtual hosting. The server only has a single IP address, but different names in the DNS correspond to that address. So www.dept.cam.ac.uk and prg.dept.cam.ac.uk both map on to the same IP address and therefore the same server. This raises the question of how the web server can distinguish requests to the two different web sites.