Solved

Tomcat Virtual Host

Posted on 2006-07-22
7
422 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 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python Assistance 7 73
Java Jpanels and Jframe 8 28
Synology - timed incremental backup to a locally attached NTFS formatted USB drive 2 24
expectj telnet failing 5 23
VM backups can be lost due to a number of reasons: accidental backup deletion, backup file corruption, disk failure, lost or stolen hardware, malicious attack, or due to some other undesired and unpredicted event. Thus, having more than one copy of …
How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now