We help IT Professionals succeed at work.

Configure Virtual Host for tomcat..

kuching
kuching asked
on
2,491 Views
Last Modified: 2013-11-15
Hi, i understand i should ask this question in the Tomcat USer mailing list, but i am sure i can get a better respond time in here comparing to them. :-)

I have amended the server.xml file from

***
..
..
      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

...
...
***

to
***
      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

      <Host name="kuching" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
***

just hoping if the user type, http://kuching and hit enter, they will see the same page like http://localhost:8080/test.jsp

But i fail. I saw this messgae on the strout file.


Catalina.start: org.xml.sax.SAXParseException: The element type "Host" must be terminated by the matching end-tag "</Host>".
org.xml.sax.SAXParseException: The element type "Host" must be terminated by the matching end-tag "</Host>".
      at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
      at org.apache.commons.digester.Digester.parse(Digester.java:1548)
      at org.apache.catalina.startup.Catalina.load(Catalina.java:532)
      at org.apache.catalina.startup.Catalina.load(Catalina.java:570)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:397)
Catalina.start: org.xml.sax.SAXParseException: The element type "Host" must be terminated by the matching end-tag "</Host>".
org.xml.sax.SAXParseException: The element type "Host" must be terminated by the matching end-tag "</Host>".
      at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
      at org.apache.commons.digester.Digester.parse(Digester.java:1548)
      at org.apache.catalina.startup.Catalina.load(Catalina.java:532)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:590)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:297)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:398)

**********

So, can anyone share with me how can i configure virtual host in Tomcat 5.0.18??

Thank you.
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Perhaps it *might* have been clearer to have said:

Access to the Tomcat server using a name in a URL is determined by your name server, not by Tomcat.  I'm not sure how this is done on Windows, but on Linux, it's done with the hosts file (in it's simplest form) or with BIND (in it's most complex).

You can test that the server is available by just using the IP address.  If that works, but the name doesn't, then the name mapping isn't set up correctly.

Commented:
Hi.

Actually there is a way you can do that but I don't think is a good Idea. anyway if you edit your server.xml and replace all "localhost" with "yourname" and do the same thing on host file of your computer it will work but just on your computer if you want to make it work accesing form a differnt computer you should add a line in that computers host file with "yourname" and your ip address.

Hope it helps

Javier

in your HOST FILE
#Host list for localhost generated by browserc.dll
yourname  127.0.0.1

127.0.0.1    yourname
216.41.185.18   auto.search.msn.com
216.41.185.18   search.netscape.com
10.64.49.242      renting


in others machines HOST FILE
#Host list for localhost generated by browserc.dll
localhost 127.0.0.1

127.0.0.1    localhost
your IP   yourname
216.41.185.18   auto.search.msn.com
216.41.185.18   search.netscape.com
10.64.49.242      renting

Commented:
I've been thinking that you really don't need to change anything on the server.xml, just adding your IP and name on the Hosts file will work, becose all access through the net are done by IP so it won't matter if you change your server name.

So just change the hosts file of the client and add your info there, if you don't have a hosts file under your windows directory just create it as I posted before, ok??

Javier

Commented:
the file is called "hosts" no host as I said in the first message.
Javier

Commented:
Again :c)

Not sure where is located on UNIX/Linux but maybe Jim can tell you that.

Javier

Commented:
;-)  On Linux it's also hosts (in /etc/).  Contents looks similar too, eg:

127.0.0.1         localhost
192.168.0.23   server
192.168.0.2     laptop
192.168.0.1     desktop

Author

Commented:
ok guys. This is the testing. please comemnt base on the number..

1. I have rem the
       <!-- orignal Setting for Virtual Host : by foong
       <Host name="localhost" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
      -->
and replace to
       <!-- orignal Setting for Virtual Host : by foong
       <Host name="kuching" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
      -->
but my machine name is called "catherine".

and i call the page, http://kuching:8080 nothing come out. and if i called the page, http://catherine:8080, the page come out.
So, can i conclude there is no way for me to make my web-pages name look more profesional like, www.kuching.web.com ?? where initially i thought should be set in the virtual host setting... to do this, like what jimmack said, i need to name my machine as "www.kuching.web.com" in order to accomplish that..

2. again, ASSUMING that i manage to change my machine name to www.kuching.web.com, so, i have change the conenction port="8080" to "80" and the result is correct. i can straight call the machine name without the 8080. TQ for this information. :-)

3. changing the hosts file in the client machine is not  a good solution. I can not control the client machine since my page is going to used by remote user. so, i didn't try that...

******

Basically my concern i am trying to change the "http://lcoalhost:8080/brh_crm"  to "http://web.crm.kuching". but i couldn't do that... please insturct or suggest what shouldl i do with the server.xml files??

I come across the webwrap.so file in the interner. what is that file ? is that anything to do with the virtual host setting??

thank you.

Commented:
1)  You've completely commented out the host definitions in both examples.  Put this back to the original value:

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

Using the above definition, you should be able to access the Tomcat server using http://catherine, providing the client you're using knows that your machine is called catherine.

2) OK.

3) You shouldn't *really* be changing the hosts files unless this is just being tested on a small local network.  If you have a larger network that that, then you need a name server to convert between the domain name and your IP address.  It's not the XML files within Tomcat that need to be changed, it's the domain->IP mapping further upstream (eg. on your network or ISPs name server).

Author

Commented:
jimmack, thanks for your reply.
this is the final one...

if let's say i need to change the http://catherine to http://catherine.web.com do i need to change the server name (my machine ) to catherine.web.com??

Commented:
Yes, the name server needs to be updated ;-)

You may be able to include both names if you want (both pointing to the same machine).

Commented:
;-)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.