Archive for September, 2009

Chapter 15: Shared Tomcat Hosting To disable the

Wednesday, September 30th, 2009

Chapter 15: Shared Tomcat Hosting To disable the HTTP Connector, either comment out or remove the default Connector setting (which follows) in server.xml: The Connector that is being used is the AJP/1.3Connector that listens, by default, on port 8009: At Apache s end, as shown in the previous chapters, a Connector for Tomcat, such as mod_jk , must be used. The AJP protocol is covered in Chapter 4 , and installing the mod_jkApache module is covered in Chapter 11. The configuration you do is similar to that in Chapter 11 , except for one difference: The JKMount directive is defined inside a VirtualHost directive in httpd.conf. Figure 15-8 shows a diagrammatic representation of how the components are related. The differences between Figure 15-2 and Figure 15-8 reflect the different information pathways. Apache Tomcat Request handler Virtual host module mod_jk module Web client AJP worker(s) AJP connector Virtual host 1 Virtual host 2 Virtual host n AJP Protocol Figure 15-8: Apache and Tomcat serving HTTP requests Here, Apache receives the HTTP request from the client. If name-based virtual hosting is used, it looks up the appropriate virtual host entry using the Host: parameter in the request. In the virtual host entry, mod_jk is configured to forward all appropriate servlet and JSP requests to the appropriate worker. The worker would use the AJP protocol to communicate with a Tomcat process started within the Apache adapter. Tomcat then examines the request to determine whether any of its virtual host definitions match the request. This is similar to the matching process in the standalone Tomcat server. The servlet response is then sent back through the AJP Connector to the mod_jkmodule. This, in turn, instructs Apache to send the reply back to the Web client. Configuring Apache Assuming that mod_jkApache module has been appropriately installed as explained in Chapter 11 , you now take a look at adding virtual host support to this configuration.

If you looking for unlimited one inclusive web hosting plan please check cheap web hosting website.

Chapter 15: Shared Tomcat Hosting Figure 15-7: test.jsp

Tuesday, September 29th, 2009

Chapter 15: Shared Tomcat Hosting Figure 15-7: test.jsp executing in the Europa virtual host The same useIPVHosts parameter is used to support IP-based virtual hosting with an AJP Connector, too. Finally, the following is a summary of the steps you need to take to configure IP-based virtual hosting in Tomcat (standalone): 1. Make DNS changes, or edit hosts file for the hosts that you wish to run Tomcat on. For IP-based virtual hosting, each host must have a unique IP address. You can use the ifconfigcommand to add a virtual interface if your machine does not have multiple network cards. 2. Create your deployment structure for the virtually hosted Web sites this is required when setting the appBase for the Web site s entries. 3. Edit Tomcat s server.xml, and add the useIPVHosts= true attribute to the Connector configuration. 4. Edit Tomcat s server.xml, and modify the directive, setting the default virtual host, as shown earlier. 5. Add entries inside the directive for each virtual host. 6. Make sure that the appBasein each points to the location of the Web site content for that host. 7. Optionally configure access log Valves and contexts for each host. 8. Restart Tomcat. You should now be able to start your browser and view the respective Web sites. You can do this using the host names of the Web sites as well as the IP addresses. Tomcat with Apache When Tomcat is used as an out-of-process servlet container along with Apache, two sets of configuration must be done: one in Tomcat and the other in Apache. For Tomcat, the configuration shown in the preceding section remains more or less the same. The only difference is that you can disable the HTTP Connector in the server.xmlconfiguration file because it is not being used.

For reliable and cheap web hosting services please check javaweb hosting website.

Chapter 15: Shared Tomcat Hosting … The Connector

Tuesday, September 29th, 2009

Chapter 15: Shared Tomcat Hosting … The Connector configuration needs the useIPVHostssetting to be set to true(the default is false). This causes Tomcat to use the server name to do the matching for the virtual host, not the passed Host attribute in the HTTP header. To test this, configure your DNS entry for callisto.domand europa.dom to different IP addresses. If your server machine has just one NIC card, you can add a new aliased interface, as shown in the following command for Linux: $ ifconfig eth0:1 netmask In the test setup, you just add entries in the /etc/hostsfile for callisto.domand europa.dom, setting them to two different IP addresses configured for the server machine: 192.168.1.2 callisto.dom 192.168.1.20 europa.dom Now edit the Connector configuration in server.xml, set useIPVHoststo true, and restart Tomcat. Then, as before, view the test JSP page for each of the domains. First view the test page for callisto.dom browse to http://callisto.dom:8080/test.jsp, as shown in Figure 15-6 . Figure 15-6: test.jsp executing in the Callisto virtual host Next, repeat this test for europa.dom by browsing to http://europa.dom:8080/test.jsp, as shown in Figure 15-7 . As you can see in Figures 15-6 and 15-7 , the two virtual domains are at different IP addresses. This time around the correct host names are printed everywhere because there is just one virtual host per IP address.

For high quality website hosting services please check tomcat web hosting website.

Chapter 15: Shared Tomcat Hosting The following list

Monday, September 28th, 2009

Chapter 15: Shared Tomcat Hosting The following list summarizes the steps you need to take to configure name-based virtual hosting in Tomcat (standalone): 1. Make DNS changes, or edit hosts file for the hosts that you wish to run Tomcat on. In name- based virtual hosting, different host names share the same IP address. 2. Create your deployment structure for the virtually hosted Web sites. This will be required when setting the appBase for the Web site s entries. 3. Edit Tomcat s server.xml, and modify the directive, setting the default virtual host, as shown earlier. 4. Add entries inside the directive for each virtual host. 5. Make sure that the appBasein each points to the location of the Web site content for that host. 6. Optionally, configure access log valves and contexts for each virtual host inside the entry. 7. Restart Tomcat. You should now be able to start your browser and view the respective Web sites. You can do this using only the host names of the Web sites ( http://callisto.dom:8080/ test.jsp, http://europa.dom:8080/test.jsp). If you use the IP address, Tomcat will serve you content from the default virtual host, as specified in your directive. IP -Based Virtual Hosting in Tomcat Support for IP-based virtual hosting in a standalone Tomcat configuration is new; it was introduced in Tomcat version 5.5, and is not supported by versions earlier than that. If you are testing name- and IP-based configurations with the same client machine, note that resolved IP addresses are often cached locally. Remember to clear the client cache before testing, or you might get spurious results. On Windows, for instance, the ipconfig /flushdnscommand clears out the local DNS resolver cache. The configuration required for using IP-based virtual hosting is similar to that of name-based, with one difference: (continued)

If you looking for unlimited one inclusive web hosting plan please check cheap web hosting website.

Chapter 15: Shared Tomcat Hosting Do the same

Sunday, September 27th, 2009

Chapter 15: Shared Tomcat Hosting Do the same for callisto.dom by using the following URL, as shown in Figure 15-4 . http://callisto.dom:8080/test.jsp Figure 15-4: test.jsp executing in the Callisto virtual host Here, as you can see from the text Welcome to the Callisto.dom web server in Figure 15-4 , the correct virtual host served up the JSP again. Note that the IP address ( 192.168.1.2) in Figures 15-3 and 15-4 are the same. In this case the Request received by = callisto.dom happens to print the correct host name, but that is just a coincidence. Finally, perform a quick check to determine whether the default host setting of the element is working properly. For this, use a host name other than the ones specified explicitly as definitions. The easiest way to do this is to try accessing the Tomcat server using the IP address 192.168.1.2 and view the results, as shown in Figure 15-5 . Figure 15-5: test.jsp executing in the Europa virtual host, using the IP address As shown by the Welcome to the Europa.dom web server text in Figure 15-5 , Tomcat serves the contents of the europa.domvirtual host, as defined in the default virtual host entry of the Engine. Now that Tomcat is working as a standalone server for the virtual hosts, the next section provides instructions for creating the configuration to work with the Apache HTTPd.

For high quality website hosting services please check tomcat web hosting website.

Chapter 15: Shared Tomcat Hosting However, if you

Sunday, September 27th, 2009

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.

Chapter 15: Shared Tomcat Hosting … Logging functionality

Saturday, September 26th, 2009

Chapter 15: Shared Tomcat Hosting … Logging functionality can be added to this virtual host by defining the AccessLogValvewithin the element: AccessLogValve is covered in greater detail in Chapter 5 . The directory specified for the log files in the Valve (i.e., /home/websites/europa.dom/logs) should be created if it does not exist. Finally, the configuration is completed by (optionally) adding the contexts to serve for this virtual host, inside the element: This configuration has added two contexts here. The first one is the default context with an empty context path. This context has to be either defined explicitly or provided automatically by Tomcat (that is, without explicitly defining it in server.xml) if there is a Web application called ROOTin the appBaseof the virtual host. Adding contexts is optional: One convenience provided by Tomcat (version 4 and later) is that it creates automatic contexts if they exist in the appBase, even if you haven t defined them in the host definition. To provide this functionality, Tomcat looks at directories inside the appBase directory. If these directories follow the Web application structure (specifically, if they contain a WEB-INF/web.xmlfile in them), Tomcat automatically provides contexts with context paths equal to the name of the directory under appBase. Remember that the default parameters for these contexts are picked up from $CATALINA_HOME/conf/ web.xml.

For reliable and cheap web hosting services please check tomcat web hosting website.

Chapter 15: Shared Tomcat Hosting The default configuration

Friday, September 25th, 2009

Chapter 15: Shared Tomcat Hosting The default configuration of the top-level element in your server.xmlfile should look like the following: The rest of the configuration would be placed inside this container element. The next step is to add the Connectors to be used for this service. Because this is a standalone server, the only Connector required to be configured is the HTTP/1.1 Connector, to enable communication with the outside world. Check your Connector definition inside the element. An example Connection definition (this is the default definition) looks like the following one shown. This configures Tomcat to listen to port 8080 for incoming Web requests. Now edit the element enclosed within the element and set the default virtual host as shown: This specifies an Engine for the service that processes incoming requests from the Connectors. After any request is received by the Connector and passed on to the Engine, the Engine examines the HTTP headers (especially the Host:tag) to determine which of the virtual host definitions that it handles should receive the request. If none of the virtual hosts seems to match the request headers, the Engine passes on the request to a default host. The name of the default virtual host is specified in the attribute defaultHost. The value of this attribute must match a definition in the Engine. In the previous configuration, the defaultHost property in the Engine element specifies that any Web requests that are not matched directly by the configured host elements should be served by the virtual host definition for europa.dom. Adding the virtual host definition of the two hosts europa.domand callisto.dom to the Engine is completed by including the following Hostelements inside the element: (continued)

If you looking for unlimited one inclusive web hosting plan please check cheap web hosting website.

Chapter 15: Shared Tomcat Hosting IP-Based Virtual Hosting

Friday, September 25th, 2009

Chapter 15: Shared Tomcat Hosting IP-Based Virtual Hosting in Tomcat, the getLocalName() method is used by Tomcat to map the request to a (virtual) host. Feel free to change these setup details for example, modifying the contents of the JSP or including additional Web application contexts to suit the server hosting policy required. Tomcat as a Standalone Server Figure 15-2 illustrates the relationship between the various components of Tomcat when Tomcat is being used as a standalone server. The Tomcat process HTTP connection handler Request Response Contexts Web client VHost 1 VHost 2 VHost n … other contexts Figure 15-2: Tomcat handling a request for a virtual host Name-Based Virtual Hosting in Tomcat In Figure 15-2 , the Web client directly sends the HTTP request to the Tomcat process listening at (default) port 8080. The HTTP Connector handles the Web client interaction. Tomcat then takes a look at the Host: header present in the HTTP request. If one is present, it tries to look up a virtual host with a name matching the one requested. If such a virtual host is found, the context parameter of the virtual host is taken and merged with the context parameters of the default configuration, and the file served accordingly. The resultant output is sent back to the Web client using the HTTP Connector again. If no context with the given virtual host is found, Tomcat tries to match the context path to the contexts that do not belong to any virtual hosts. If one is found, that context is used to send back the results. If no such context is found, either the default (with the empty context path) context is used to send back the result (in which case, the context path is matched to a physical directory or file name) or an HTTP 404 error is generated and sent back to the client. Adding a virtual host is as simple as adding an entry, with entries for each additional virtual host in server.xml. Once you have made these additions, you simply restart Tomcat to use the virtual host definitions.

If you looking for unlimited one inclusive web hosting plan please check web hosting plan website.

Chapter 15: Shared Tomcat Hosting Finally, keeping these

Thursday, September 24th, 2009

Chapter 15: Shared Tomcat Hosting Finally, keeping these two entities (static files and Web applications) separate aids in keeping the directory structure clean and more maintainable, as shown in Figure 15-1 . /home/websites/ europa.dom/ callisto.dom/ web/ webapps/ web/ webapps/ Figure 15-1: Sample directory structure for a virtual host environment For the purposes of providing a simple test example, create a sample JSP file named test.jsp, in the document base of the default context Web application of each of these domains. For example, the file /home/websites/europa.dom/webapps/ROOT/test.jspshould contain the following simple code: <% out.println( Welcome to the Europa.dom web server.
); out.println ( Request sent to = + request.getServerName() + : + request.getServerPort() +
); out.println ( Request received by = + request.getLocalName() + [ + request.getLocalAddr() + ]: + request.getLocalPort() +
); %> Create a similar file as /home/websites/callisto.dom/webapps/ROOT/test.jsp. Remember to change the names for the callisto.domdomain. Note the use of the javax.servlet.ServletRequestmethods in the servlet, namely request .getServerName()and request.getLocalName(). These are for testing the script to ensure that the virtual host settings are correct. The getServerName() method returns the name of the server (or IP address) that the HTTP request was sent to. The getLocalName() method returns the name of the server that actually received the request. In this example, both are the same ( callisto.domand europa.dom respectively), but this need not always be the case. Also, as you will see in the section

For high quality website hosting services please check tomcat web hosting website.