Solved

Tomcat Virtual Host

Posted on 2006-07-22
7
419 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Author Comment

by:suprapto45
Comment Utility
Hi Holger,

Thanks much. I will try it.

David
0
 
LVL 16

Author Comment

by:suprapto45
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much

David
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

743 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

17 Experts available now in Live!

Get 1:1 Help Now