Chapter 15: Shared Tomcat Hosting However, if you need to override some global parameters to these contexts, that configuration is required within the elements. Examples include logging for this context in a separate file, context parameters, resource definitions, and so on. The server.xml is not the only place where the context can be defined; you can also define it in a context.xml file, and place that file inside your Web applications META-INF directory. In this example, for instance, it would be at /home/websites/europa.dom/webapps/ROOT/META-INF/context.xml for the default (ROOT) context. This completes the virtual host definition for europa.dom. For the virtual host callisto.dom , add another virtual host entry similar to that of europa.dom. After completing these changes to $CATALINA_HOME/conf/server.xml, save the file and restart the Tomcat service. Finally, set your DNS entries to point europa.domand callisto.dom to the correct IP address of the server the same in this case. For this test, instead of setting up an entry in a DNS server, you just add the following lines in your hosts file on the client and server machines: 192.168.1.2 callisto.dom europa.dom Now, check the test JSP file in the europa.dom virtual host using the following URL, as shown in Figure 15-3. http://europa.dom:8080/test.jsp Figure 15-3: test.jsp executing in the Europa virtual host As you can see from the Welcome to the Europa.dom web server text in Figure 15-3 , the correct virtual host served up the JSP. The Request sent to text shows the result of the request.getServerName() method call, and that the request was indeed sent to europa.dom. Why then does the request .getLocalName() method call print out Request received by = callisto.dom ? This is because the IP address maps to both callisto.domand europa.dom in the hosts file (or DNS entry), and Tomcat resolves that to be one of them in this case callisto.dom. This should be considered while developing a Web application to be deployed in shared hosting situations; the server name returned by the javax.servlet.ServletRequestmethods may not always be what you expect.
For high quality website hosting services please check tomcat web hosting website.
This entry was posted
on Sunday, September 27th, 2009 at 4:53 am and is filed under tomcat.
You can follow any responses to this entry through the RSS 2.0 feed.
Responses are currently closed, but you can trackback from your own site.