Directing DNS to different ports

Solution 1:

you can't do that on DNS level.

what you can do is have your server1 (port 80) record as it is, then create server2 record (you can use same IP) and have http redirect to server1:8080 (you can do this with apache rewrite):

<VirtualHost IP:80>
ServerName server2
RewriteEngine on
RewriteRule ^(.*)$ http://server1:8080/ [R,L]
</VirtualHost>

Solution 2:

DNS can't help you here: The only ports it knows about are its own (53) and the ones encoded in SRV records.

If I remember correctly Tomcat allows you to set up name-based virtual hosts, which is what it sounds like you want (stick your apps in different named vhosts rather than on different ports).

Moving your "port 8080" app to port 80 on another IP is also an option.

If you need to keep the app on port 8080 for some reason clever use of mod_rewrite or HTTP/301 redirects can be made to do what you want ("If the host is "example2" redirect the user to port 8080"). Deeper levels of complexity are left as a (painful) exercise for the reader.

Solution 3:

You should also be able to solve this at the firewall level using two NAT rules, assuming the websites can be bound to seperate IPs. You NAT one of the websites through from external port 80 to internal port 8080.

As an aside, I prefer a port other than 8080, as that's conventionally used for Web Proxies.