Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Tomcat Virtual Host

Posted on 2006-07-22
7
Medium Priority
?
450 Views
Last Modified: 2013-11-24
Hi guys,

I know that this would be better if we use Apache to define the Virtual Host in Tomcat. However, I am still testing my application so it would be good if I just can use Tomcat only.

       <Host name="mortgagecalc.tus" appBase="MortgageCalculator">
      <Context path="/MortgageCalculator" docBase="MortgageCalculator"
            debug="5" reloadable="true" crossContext="true">
            
      </Context>
       </Host>

I have it in my <TOMCAT_HOME>/MortgageCalculator/ROOT/index.jsp

These are my questions.
1. Is that the right way to do it?
2. Do I need to define any DNS Server that will map the mortgagecalc.tus with my local IP Address? Is it local DNS Server or etc?
3. I just want to test it locally (within my networks) so that people won't need to type in my IP Address (192.168.0.16) but only defining the name of mortgagecalc.tus.

Well, my networking knowledge is limited. I am learning it now :)

Thanks
David
0
Comment
Question by:suprapto45
  • 4
  • 3
7 Comments
 
LVL 16

Author Comment

by:suprapto45
ID: 17161340
I think that my local machine needs to be a DNS Server where I can map the IP with the name. Am I right? Then it means that I need to be in Windows NT4 Server or Win 2K Server or perhaps...I can test in my Linux RedHat box.

David
0
 
LVL 6

Accepted Solution

by:
Holger101497 earned 2000 total points
ID: 17162950
For your question:

#1) I'm not 100% sure, might be ok. You can find out mor easily after solving #2+#3 :-)
#2) No, not in your case. Or rather: You would need to define the DNS server for everybody who's using your app, so you'd need to contact your network admin (if you're in a company) and all of this is a LOT of trouble. There are two easier solutions:
2a) For yourself (first step in testing), you can add your desired domain to your "hosts". In Windows, it's WINDOWS\system32\drivers\etc\hosts. In Linux, I'm not sure, it might be "/etc/hosts".
You know you've done this correctly when you can type "ping mortgagecalc.tus" and it says "reply from 192.168.0.16" :-)
Everybody else who wants to use it would also have to configure this!!!
2b) If you want to use it in your local network, it's really the easiest to use your computername! My computer name is "HolgerX25" and in a "normal company network", all computers are reachable by name. Again, you can easily try this by pinging your name from a different machine!
#3) see #2b) :-))

One explanation about virtual hosts: They are completely independent from ANY DNS setup.
When you type "http://somehost/page.html" in a browser, the browser resolves the name to an IP-address, so yes, the name must resolve to an IP address, but you can see easy examples of "faking (substituting) that" above.
Then it sends the request to the server AND sets an "attribute" in the header to let the server know which host was requested. If one server handles multiple domains, this attribute lets the server know what to do with the request. It's just a help for the server, nothing else. If you serve the same pages for all domains in your tomcat, messing with virtual hosts just causes useless work! Tomcat will by default handle everything it gets! You really only need Virtual hosts if it makes a *DIFFERENCE* if the user typed http://192.168.0.16/page.html or http://mortgagecalc.tus/page.html

From your post, I don't think it does. Think about a big hoster that serves 500 domains for different users all on the same machine and from the same Apache instance (!).

So your steps are:
#1) Make sure the "server" is reachable from the client using the desired name (easiest: computer name). When the ping succeeds, proceed to #2 :-)
#2) Do NOT use a virtual host in Tomcat, see if it works as desired :-)

I hope this helps a bit, don't hesitate to ask more specific questions.

Holger
0
 
LVL 6

Expert Comment

by:Holger101497
ID: 17162957
P.S.: server names don't "need" a top level domain.
http://server/page.html works just as well as http://server.tus/page.html, so everybody in my company can always do http://HolgerX25/somePage.html to access my Apache... NO additional network configuration (or virtual hosts) needed...
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 16

Author Comment

by:suprapto45
ID: 17163031
Hi Holger,

Thanks much. I will try it.

David
0
 
LVL 16

Author Comment

by:suprapto45
ID: 17163043
Thanks Holger,

I can work it out successfully :). Thanks.

However, I am confused about one more thing now. Ok, I can modify WINDOWS\system32\drivers\etc\hosts to map mortgagecalc.tus into my IP which is 192.168.1.16. So why do I need to configure <host> again in my Tomcat. Would that be redundant? In my opinion, yes.

David
0
 
LVL 6

Assisted Solution

by:Holger101497
Holger101497 earned 2000 total points
ID: 17163193
Short answer: Yes.

Long answer: See above *g*
> you really only need Virtual hosts if it makes a *DIFFERENCE* if the user typed http://192.168.0.16/page.html or http://mortgagecalc.tus/page.html
:-)

I can tell you that I have NEVER configured the "host"-element in Tomcat (just always use "localhost") and everything has always worked for me for any hostname I chose to use.
This goes as far as "internal access" combined with "external access" where my computer is associated with a DynDNS address and one port in the firewall being open.
Also, I "mix and match" accessing the Tomcat port (8085 for Tomcat 5 in my case) directly (usually for localhost:8085) and accessing it through Apache from "outside" (http://myname.dnsalias.com/). Everything's always worked...

I have used Virtual Hosts in Apache, though... But even there, it was not strictly needed...
However, you might want to take a look at this just FYI:
http://tomcat.apache.org/tomcat-5.0-doc/config/host.html

And for your other question:
> Ok, I can modify WINDOWS\system32\drivers\etc\hosts to map mortgagecalc.tus into my IP which is 192.168.1.16

As also mentioned above, YOU can use http://mortgagecalc.tus/ now, but nobody else can! Everybody who would want to use that address would have to enter it into HIS/HER local hosts-file.
That's why I recommended using the computer name.

Holger
0
 
LVL 16

Author Comment

by:suprapto45
ID: 17166105
Thank you very much

David
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question