1 IP, multiple web servers?

Notice: Page may contain affiliate links for which we may earn a small commission through services like Amazon Affiliates or Skimlinks.

TeeJayHoward

Active Member
Feb 12, 2013
376
112
43
I've got two domains. Right now, they're both pointing to the same IP address. I'd like it if I could set up something that figured out what domain the user typed in, and forward the traffic to one of two servers based on that information. Is it possible to do something like this? If so, what is it called?

Example:
Bob.com -> Web Server 1
Bob.net -> Web Server 2
 

badatSAS

Member
Nov 7, 2012
103
0
16
Boston, MA
Apache is also very capable of handling virtual hosts with multiple hostnames on a single IP address being directed to separate "virtual webservers" with separate content.

If I had 4 minutes to do this I would set up Apache with two virtual hosts (bob.net and bob.com) on port 80 of my public ip address, and have it redirect to either bob.net:81 or bob.com:82 within the virtualhost definition which would be setup as a port forward at the NAT/firewall/router from 81-->Webserver1 and 82-->Webserver2 (assuming that neither Webserver1 or Webserver2 was the machine doing the redirection)
 

rubylaser

Active Member
Jan 4, 2013
846
236
43
Michigan, USA
You don't even need to use ports other than port 80. Apaches vhost setup can be as simple as *:80 with the ServerName set to the proper FQDN.
 

badatSAS

Member
Nov 7, 2012
103
0
16
Boston, MA
ruby, my suggestion above was if he required it to pass through to two seperate hosts behind NAT on the single IP directly, vs using the server on the single ip as a reverse proxy (which is the proper way to do this)
 

rubylaser

Active Member
Jan 4, 2013
846
236
43
Michigan, USA
ruby, my suggestion above was if he required it to pass through to two seperate hosts behind NAT on the single IP directly, vs using the server on the single ip as a reverse proxy (which is the proper way to do this)
Sorry, I didn't want to sound like I was saying you were incorrect. I was just trying to add if these are on the same box, you don't need to use extra ports. If you are trying to pass through to multiple hosts, then you are exactly right:)

I frequently see questions like this in the Server Section of the Ubuntuforums, so I assumed that TeeJayHoward just wanted to redirect Bob.com to one application on the same host and Bob.net to another application on the same host (I could have completely misunderstood though).
 
Last edited:

Jeggs101

Well-Known Member
Dec 29, 2010
1,529
241
63
I've got two domains. Right now, they're both pointing to the same IP address. I'd like it if I could set up something that figured out what domain the user typed in, and forward the traffic to one of two servers based on that information. Is it possible to do something like this? If so, what is it called?

Example:
Bob.com -> Web Server 1
Bob.net -> Web Server 2
I typed bob.com into my address bar --- then thought 2x about it. Odds are wouldn't take me somewhere chrome'd want me to go!
 

spazoid

Member
Apr 26, 2011
92
10
8
Copenhagen, Denmark
What if you have multiple webservers AND multiple ports?

In my case I have sites for CouchPotato, Sick Beard and SABnzbd on one host (with different ports) and other sites on different servers. I would love to be able to access these with cp.mydom.com, sb.mydom.com etc, all on port 80.

I haven't really been able to find a good _thorough_ walk-through - all of the ones I've found (including the one linked above) assumes some level of skill in web hosting (which I absolutely do not possess).
 

rubylaser

Active Member
Jan 4, 2013
846
236
43
Michigan, USA
You will need to create DNS hostnames for each of those domains and point them all at the host machine's ip address. You will also need to create rewrite rules for each application. With a self professed web hosting knowledge of zero, this is rather complicated:)

At home, I have setup all of these services to run on sequential ports, and setup a DNS record to point to that machine. This works fine for me. If you really wanted to do this the easy way, you could make a simple HTML landing page with images for each service and a link to the relevant service or use something like this.
 
Last edited:

badatSAS

Member
Nov 7, 2012
103
0
16
Boston, MA
The problem with doing a walkthrough for this is that it would be vastly different instructions depending on:
Your DNS server
Your router/network configuration
Operating System
etc..
 

Patrick

Administrator
Staff member
Dec 21, 2010
12,513
5,804
113
The problem with doing a walkthrough for this is that it would be vastly different instructions depending on:
Your DNS server
Your router/network configuration
Operating System
etc..
Yea... reminded me that on the list of things I want to but don't have time to do is a basic HAproxy setup :-/