• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can Tomcat serve apps on two different IP addesses, both on port 80

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are trying to create a DNS name that points to a Java/Tomcat app. Since DNS cannot handle port numbers, my network guys tell me, I need to have some way for the Java app to respond only on the IP defined in DNS for that app. For instance, we have configured the DNS alias TestApp to point to 192.168.200.10. Can I configure Tomcat to fire up the TestApp application on port 80 of that address? The other apps in that Tomcat container will continue respond using the default IP that Tomcat recognized upon installation, i.e., 192.168.200.20/ProdApp1, 192.168.200.20/ProdApp2. BTW, we are not really using 192 addresses, that is just an example.

Our Tomcat is running on a Windows 2003 server with one NIC.

The point of this is to allow our corporate intranet users to just type, for example, http://TestApp and get to the desired application. They don't want to type http://TomcatServer/Apps/TestApp. Of course the real string is longer.
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming your tomcat /webapps directory looks like this:


All you need to do to make a request to "http://TestApp" resolve to webapp "TestApp.war" is to rename "TestApp.war" as "ROOT.war" and make Tomcat listen on port 80 by specifying it in server.xml HTTP connector element (http://tomcat.apache.org/tomcat-6.0-doc/config/http.html).
Any webapp named "ROOT.war" will not need the webapp name in URL.
It's not necessary to have a separate IP. Both domains "TestApp" and "TomcatServer" can point to the same IP as long as that IP is accessible to all users of your webapp.

If for some reason, you want to have separate IPs (for example, same NIC with multiple IPs), then Tomcat by default binds to all available IPs on port 80 - you don't have to do anything special.

The side effect of all this is that http://TomcatServer (without any webapp name) too will resolve to "ROOT.war", and "http://TestApp/ProdApp1" will resolve to "ProdApp1.war".
If that is not what you want, then one solution is to use separate "Virtual hosts" (http://tomcat.apache.org/tomcat-6.0-doc/config/host.html) for each domain.
The Virtual Host concept is for multi tenancy in a shared Tomcat instance. It allows multiple domain names to share the same IP, but resolve to different sets of webapps. Each Virtual Host can then have its own webapps directory.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there still people out there who think they have to type URLs? Just send them an e-mail containing the long and complicated URL and tell them to click on the link. And surely they know how to use the "Favorites" menu in their browser?
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Are there still people out there who think they have to type URLs? Just send them an e-mail containing the long and complicated URL and tell them to click on the link. And surely they know how to use the "Favorites" menu in their browser?





Sometimes you're not in a position to do this. I've nailed myself trying to show off obscured apps to people when I couldn't remember the full URL and didn't happen to have had the foresight to "email myself" not was it a browser favorite on the device being used.

The biggest obstacle to putting a specific app on port 80 is that it's port 80. That means that a lot of systems would require Tomcat to run with root privileges, and thus become more vulnerable to security exploits.

Exactly one and only one application can listen on any given port, whether it's port 80 or port 8080 or whatever. So the second obstacle is that there cannot be an existing competitor for that port.

Tomcat can listen on as many ports as you want to configure in, so a virtualhost that owns a simple URL/port is not itself a major problem. However it's a lot easier in most cases to set up a proxy server to do that for you, thanks to the 2 obstacles I listed above. SO, for example, you could setup a copy of Apache, activate mod_proxy, define a virtual host or 2, and then people could use URLs such as "http://testserver/testapp1", where Apache proxies for something like "testserver3:8080/testapp1". You could also go the full virtual host route (http:/testserver), but that means more DNS work, and people can probably be trusted to remember "testserver/testapp". When they can be trusted to remember anything at all.
 
Dave Knapp
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Are there still people out there who think they have to type URLs? Just send them an e-mail containing the long and complicated URL and tell them to click on the link. And surely they know how to use the "Favorites" menu in their browser?



That was our first idea, just mail out a shortcut. Turns out the application owner just wants to tell sales folks, who are not known for their technical prowess, to just type 'TestApp' (not its real name) and magically the app would run in their browser. There are lots of these folks who don't have offices, are just in for the day, yada yada.
 
Dave Knapp
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:Assuming your tomcat /webapps directory looks like this:


All you need to do to make a request to "http://TestApp" resolve to webapp "TestApp.war" is to rename "TestApp.war" as "ROOT.war" and make Tomcat listen on port 80 by specifying it in server.xml HTTP connector element (http://tomcat.apache.org/tomcat-6.0-doc/config/http.html).
Any webapp named "ROOT.war" will not need the webapp name in URL.
It's not necessary to have a separate IP. Both domains "TestApp" and "TomcatServer" can point to the same IP as long as that IP is accessible to all users of your webapp.

If for some reason, you want to have separate IPs (for example, same NIC with multiple IPs), then Tomcat by default binds to all available IPs on port 80 - you don't have to do anything special.

The side effect of all this is that http://TomcatServer (without any webapp name) too will resolve to "ROOT.war", and "http://TestApp/ProdApp1" will resolve to "ProdApp1.war".
If that is not what you want, then one solution is to use separate "Virtual hosts" (http://tomcat.apache.org/tomcat-6.0-doc/config/host.html) for each domain.
The Virtual Host concept is for multi tenancy in a shared Tomcat instance. It allows multiple domain names to share the same IP, but resolve to different sets of webapps. Each Virtual Host can then have its own webapps directory.



How do I get it to respond on a different IP from the one that is statically assigned to the single NIC? Do I need to do some sort of configuration to the NIC itself? I am guessing that just changes to Tomcat is not enough. Would not the nic with a static IP effectively block packets that do not have its IP address?
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Applications listen to ports, not NICs. However, NICs only listen to broadcasts and to traffic specifically addressed to that NIC. But a NIC can be set up to listen at multiple IP addresses, and I have production servers that do so. I forget the proper term, but these other addresses are alias addresses and on the RedHat Linux platform, they're fairly easy to set up.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How do I get it to respond on a different IP from the one that is statically assigned to the single NIC? Do I need to do some sort of configuration to the NIC itself?



In your post, you've mentioned OS is Windows 2003. Assigning multiple IPs to the same NIC is possible in Windows too, from "Network connection properties > Internet Protocol Version 4 Properties > Advanced" dialog.

On a different note, it's not clear to me why you would need a dedicated IP address for this webapp. If the problem is only to have a friendly URL without any webapp name in it, then the "ROOT.war" name - optionally with virtual host configured - should solve the problem. What benefit will a dedicated IP address provide in this situation?
 
Dave Knapp
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:

How do I get it to respond on a different IP from the one that is statically assigned to the single NIC? Do I need to do some sort of configuration to the NIC itself?



In your post, you've mentioned OS is Windows 2003. Assigning multiple IPs to the same NIC is possible in Windows too, from "Network connection properties > Internet Protocol Version 4 Properties > Advanced" dialog.

On a different note, it's not clear to me why you would need a dedicated IP address for this webapp. If the problem is only to have a friendly URL without any webapp name in it, then the "ROOT.war" name - optionally with virtual host configured - should solve the problem. What benefit will a dedicated IP address provide in this situation?



Good question. We have multiple Java apps on this server, but they don't all require the friendly URL. Port 80 is already in use.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic