If you want to host your web server on the standard HTTP (80) or HTTPS (443) ports, I think you cannot have two different machines answer depending solely on the domain name.
The thing is, when you access some site, you are not accessing it via a domain name - you are just using DNS to map that domain name to an IP. The reason you can host multiple sites on the same IP is the Host header - see section 14.23 Host
of RFC 2616:
How this works is the following. Let's say we have two domains a.example.com and b.example.com pointing to the same IP, say 10.0.0.10. Client, usually using some Web browser, asks DNS for the IP of a.example.com. DNS replies back with 10.0.0.10. Client then sends something like:
Host: a.example.com
When your web server receives this, it can then determine that you actually want a.example.com and not b.example.com (or possibly other virtual hosts on that web server).
In your example, however, you don't have one server - you have two servers. Router would need to route to one of them based solely on the IP - the Host header is processed on the application layer while routing is done on the IP layer (see TCP/IP model). While some routers do some decisions based on the application layer, I don't think any can go that deep into the packet to examine the HTTP headers and route based on that result.
What you can do is:
- Make one of the two VMs the default and then proxy through to the other one
- Make a third VM that will proxy to both current VMs
See e.g. this for more information about virtual hosts:
See e.g. these about setting up a reverse proxy:
Here is the reference documentation for the modules that can be used to make reverse proxy:
Hope this helps.