Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Imagine I have 10 different domains. All these domains have an A record to a single IP Address. There are ten different services hosted on this one IP. Let's assume they listen from port :80 to :90. The default port of the used protocol is :80 and I can't force the users to append an :82 to the domain name.

And here's the problem: I want to internally forward the :80 depending on the used domain name.

  • domain0.com:80 --> :80
  • domain1.com:80 --> :81
  • domain2.com:80 --> :82
  • domain3.com:80 --> :83
  • ...

I googled around and came across iptables. Is this what I'm looking for?

share|improve this question
    
What is running the domains? Windows, Linux? –  Dave M Mar 5 '12 at 19:49
1  
What webserver are you using? Are these domains actually domains, or subdomains/"hosts"? You may want to have a looking into Virtual Hosts. –  NcA Mar 5 '12 at 19:50
    
What is the reason for using different ports rather than just setting up host header values? (Win) –  Paul Ackerman Mar 5 '12 at 19:54
    
I'm using the latest Ubuntu Version and have real domains. And I'm not talking about HTTP, actually it's Minecraft. –  buschtoens Mar 5 '12 at 21:09
    
Unless the minecraft protocol provides an equivalent of the HTTP Host: header, you're SOL. Get more IPs. –  womble Mar 5 '12 at 21:39

2 Answers 2

up vote 3 down vote accepted

Generally this can not be done like that. When the client connects via TCP and/or UDP the server has no information on what domain the client used to request the server's IP address.

Since you are mentioning port 80 you could be talking about HTTP traffic. In that case this distinction can be made since the HTTP protocol also transfers the selected domain name. You could use a HTTP server like Apache and configure a virtual host for each domain that acts as a reverse proxy and forwards the traffic to the correct port. A configuration like this could look something like that:

<VirtualHost *:80>
    ServerName domain1.com

    ProxyPass / http://server-ip:81/
</VirtualHost>

For this to work the modules proxy and proxy_http need to be activated.

share|improve this answer
    
Okay, I finally accepted your answer, because in generally for HTTP this is truethy. But you can't do that with - let's say - Minecraft, which doesn't implement the domain into its protocol. –  buschtoens Jul 24 '12 at 1:37

You can do exactly what you ask using a proxy or loadbalancer such as haproxy. But if you just want to host multiple sites on the same IP then using headers would be the standard method.

If you are trying to host multiple SSL sites on the same IP then neither of these methods will work because the header and the url are encrypted.

share|improve this answer
    
Server Name Indication means that you can now host multiple SSL sites on one IP address as long as you don't care about anyone on Windows XP or anything older than IE8. –  Ladadadada Mar 5 '12 at 20:44
1  
Doesn't work when the protocol doesn't provide any sort of server name indication, as the OP has (finally) clarified. –  womble Mar 5 '12 at 21:38
    
Plus there still is not enough widespread support for it yet to be relied upon. –  JamesRyan Mar 6 '12 at 10:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.