How to send requests to different web servers with the same IP?

bistwo

Distinguished
Jul 27, 2011
202
0
18,760
I have two servers running under the same network, with only one external IP. How can I set up the servers so that they answer requests based on the subdomain requested? For example a.example.com goes to one server and b.example.com goes to another, but both requests are coming from port 80 to the same external IP?

Both web servers run Microsoft Windows operating systems and use IIS.
 
well, you would need to differentiate the two servers by some means.
Both servers cannot run on same IP and port.

Now, as far as I understood the question, you have custom dns entries:
a.example.com that points to your routers external IP
b.example.com that points to your routers external IP

both IP's are same and as far as I know, no DNS entry can add custom port change to the end (a.example.com:81) to make the server be different.
Since IP traffic goes ONLY by numbers, Router only knows who the packet sender is, not what DNS entry it used to get router IP.
Based on that, what you are asking is impossible.
Your router will NEVER know if person asked for a.example.com, b.example.com or xyz.joke.com as long as it points to routers external IP.

You would need two external IP's or people would need to specify the 2nd server port as different when connecting:
a.example.com (for port 80)
a.example.com:81 (for port 81)

and then you would forward port 80 traffic to internal port 80 and port 81 traffic to internal IP/port you want.


edit: the post doesn't take into account if the router can do ip/port forwarding since even if it could, the situation as described by OP is impossible to attain since router will never know what DNS entry people requested the page with.
 
I'm not sure how hosting companies do it, but they do it all with the same IP. When I had hosting, I had like 10 domains under 1 IP. It's all based on the sub-domain or domain name with DNS redirects, so that blahblah.com would go to /home/www/files/blahblah/ and woozwooz.com would go to /home/www/files/woozwooz even though woozwooz and blahblah were both hosted on the same machine and save web server. The dNS redirection allows it to tell it what subfolder to go to.