Solved

Tomcat Virtual Host

Posted on 2006-07-22
7
436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
robocopy 33 157
Hyper V Cluster/Storage Question 5 92
maven not picking latest jar instead picking old jar from .m2 12 75
Automated Archive of Laptop Documents to the Cloud 7 78
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
VM backup deduplication is a method of reducing the amount of storage space needed to save VM backups. In most organizations, VMs contain many duplicate copies of data, such as VMs deployed from the same template, VMs with the same OS, or VMs that h…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

752 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