# How to switch between different webservers on same IP based on hostname?

At my place I have 4 servers, each running Win2008r2-WEB running as webserver with all a different kind of server running (TomCat, IIS, Apache, ZendServer), each server also has a different IP-address (10.0.0.0/24)

Is there a way to route traffic to each one of the servers based on hostname? (ex: apache.domain.org, iis.domain.org, tomcat.domain.org, zend.domain.org)

Obviously, I can't change the A-records to the internal IP's, and I do not have access to change ports.

Also due to proxy reasons, I can't just use other ports, I can only access :80 incoming.

-

What you'd need to do to get this to work would be to have a single one of the existing web servers (or a separate one that's dedicated to the task) be configured as a reverse proxy.

It would be responsible for getting the request on the public address and reading the host header, then proxying the request to the appropriate private address depending on the host that was requested.

Popular software packages for this task are Apache (you could use your existing instance), nginx, or HAProxy. There's plenty of information in questions here on configuring these appropriately ("reverse proxy" is the search term that'll get you there), but if you have a specific one of these software packages in mind then I can edit this answer with an example config.

Edit: example Apache config:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName apache.domain.org
ServerAlias www.apache.domain.org
# For this one, we'll imagine that you want to serve these resources from
# the local server.  If you want do use a separate Apache instance instead,
# then copy one of the other hosts for this one.
DocumentRoot "C:\path\to\site\files"
<Directory "C:\path\to\site\files">
Order allow,deny
Allow from all
</Directory>
# Any other directives you need for the content here
</VirtualHost>

<VirtualHost *:80>
ServerName iis.domain.org
ServerAlias www.iis.domain.org
# Replace the URL below with the URL of the IIS server - make sure
# to keep the trailing slash.
ProxyPass / http://10.x.x.1:80/
ProxyPassReverse / http://10.x.x.1:80/
</VirtualHost>

<VirtualHost *:80>
ServerName tomcat.domain.org
ServerAlias www.tomcat.domain.org
# Replace the URL below with the URL of the Tomcat server - make sure
# to keep the trailing slash.
ProxyPass / http://10.x.x.2:8080/
ProxyPassReverse / http://10.x.x.2:8080/
</VirtualHost>

-
I'd go with the easiest to configure, either Linux or Windows (windows preferred, though). Can you post a example config? –  Sander Jan 2 '12 at 9:46
@Sander I've added an example Apache config, since it's the most Windows friendly. –  Shane Madden Jan 2 '12 at 18:16
Thanks! The config works like a charm ! <3 –  Sander Jan 16 '12 at 12:35

Is there a reason why Name based Virtual Hosting isn't an option?

http://httpd.apache.org/docs/2.0/vhosts/name-based.html

The 10.x addresses are the internal addresses, and as you mention, DNS won't help you there. Do all the servers respond to the same external IP address? (You could then create A records for each subdomain in the DNS, each pointing the same IP ... or better yet, using CNAMES.)

-
Externally is all the same IP on the same port.. Do keep in mind I'm asking for 4 different physical servers.. –  Sander Jan 1 '12 at 23:10

at least with IIS, you can use host headers to detect which web site should respond based on a DNS name. So if you want IIS site 1 to respond to sites such as "testsite1.com and www.testsite1.com" you simply add those into the host header of that given IIS site. Then on a second iis site, you could have "testsite2.com and www.testsite2.com" asigned and IIS will pickup on those domains. DNS as far as A vs. CNAME when it comes to host headers is irrelevant. IIS will work with both.

Typically what we do with IIS, is we create an A record for the servername it self, and then we use CNAME's to forward to the servernames A record.

So Webserver A = 10.10.10.10 testsite1.com CNAME = webserver testsite2.com CNAME = webserver

IIS will then know where to send the site based on the DNS name.

-