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.

Greetings all,

I have a server with two tomcat services (one being run on port 80, the other 8080).

What I'm wanting to achieve is to have two different DNS records for these two ports, so they'll be accessible via:

http://example1/
http://example2/

Instead of

http://example1/
http://example1:8080/

I know this isn't possible using DNS A records, but does anyone know of another solution I could look into?

Thanks,

Andrew

share|improve this question
    
If you want to solve this via DNS, try SRV-Records. I explained it [here][1] [1]: serverfault.com/questions/313112/… –  Subito Sep 20 '11 at 11:35
add comment

3 Answers

up vote 5 down vote accepted

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>
share|improve this answer
    
...and this would be the "clever use of mod_rewrite" I mentioned :-) –  voretaq7 Feb 3 '10 at 7:23
    
Excellent, this is what I needed. Thanks very much to both of you. –  Andrew Feb 3 '10 at 7:27
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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