Configuring a virtual host on Tomcat

Source: Internet
Author: User

1 , Tomcat Server's Server.xml file

(1) Tomcat components

The TOMCAT server is comprised of a series of configurable components, the core of which is the Catalina Servlet container, which is the top-level container for all other Tomcat components. Tomcat components can be configured in the <catalina_home>/conf/server.xml file, and each Tomcat component corresponds to a configuration element in the Server.xml file.

(2) The relationship between Tomcat components

The following code shows the relationships between the various Tomcat components in XML:

<Server>

<Service>

<connector/>

<Engine>

<Host>

<Context>

</Context>

</Host>

</Engine>

</Service>

</Server>

(3) Description of each Tomcat component

In the XML code above, each element represents a Tomcat component. These elements can be divided into 4 categories:

L top-level class elements: mainly include <Server> elements and <Service> elements, which are located at the top level of the entire configuration file.

L Connector class element: Represents a communication interface between the customer and the service, responsible for sending the customer's request to the server and delivering the server's response to the customer.

L Container class element: Represents the component that processes customer requests and generates response results, there are 3 container class elements, which are Engine, Host, and Context. The Engine component processes all customer requests for a specific service component, and the host component processes all customer requests for a specific virtual host, and the Context component processes all customer requests for a particular WEB application.

L Nested class elements: nested class elements represent components that can be added to a container, such as <Logger> elements, <Valve> elements, and <Realm> elements.

(4) <Server> elements

The <Server> element represents the entire Catalina Servlet container, which is the top-level element of the Tomcat instance and is defined by the Org.apache.catalina.Server interface.

The <Server> element can contain one or more <Service> elements, but the <Server> element cannot be a child element of any other element.

(5) <Service> elements

The <Service> element is defined by the Org.apache.catalina.Service interface, which contains a <Engine> element, and one or more <Connector> elements, which < The connector> element shares the same <Engine> element.

(6) <Connector> elements

The <Connector> element is defined by the Org.apache.catalina.Connector interface. The <Connector> element represents the component that actually interacts with the client, and it is responsible for accepting the customer's request and returning the response results to the customer.

(7) <Engine> elements

The <Engine> element is defined by the Org.apache.catalina.Engine interface. Each <Service> element can contain only one <Engine> element. The <Engine> element handles customer requests that are accepted by all <Connector> elements in the same <Service> element.

The <Engine> element can include the following sub-elements:

<Loggor>

<Realm>

<Valve>

<Host>

(8) <Host> elements

The <Host> element is defined by the Org.apache.catalina.Host interface. A <Engine> element can contain multiple <Host> elements. Each <Host> element defines a virtual host that can contain one or more Web applications.

The <Host> element can include the following sub-elements:

<Loggor>

<Realm>

<Valve>

<Context>

(9) <Context> elements

The <Context> element is defined by the Org.apache.catalina.Context interface. The <Context> element is the most frequently used element. Each <Context> element represents a single Web app running on a virtual host. A <Host> element can contain multiple <Context> elements.

The <Context> element can include the following sub-elements:

<Loggor>

<Realm>

<Valve>

<Resource>

<ResourceParams>

2 , configure the domain name for the host

(1) Edit the Hosts file under C:\WINNT\system32\drivers\etc, in which the domain name of the map to the native IP address is increased

(2) This example is

127.0.0.1 www.sina.com

(3) Save the file

3 , modify Tomcat under the C:\jakarta-tomcat-5.0.19\conf\server.xml file to add a host Host the Settings

The host tag is used to configure the virtual host, that is, multiple domain names can point to a tomcat,<context> is a child element of the host tag, it represents a virtual directory, it has two properties, path is equivalent to the virtual directory name, and The docbase is the specific file location.

<contextpath= "" docbase= "ROOT" debug= "0"/>

</Host>

Attention:

(1) You can copy all the settings of the host of the localhost that you own with Tomcat, then rename "localhost" to www.sina.com.

(2) must ensure that there is at least one <context path= "" docbase= "root" debug= "0"/> root Web application setup project exists between <Host></Host>.

(3) Depending on the needs of the application, you can set up other <Context> settings for other Web applications based on the host name in <Host></Host>.

4 , start Tomcat and then browse this Web Application

Input http://www.sina.com:8080/WebMis/index.jsp

5 , this example can also be used to localhost the default host name to access

http://localhost:8080/WebMis/index.jsp

Configuring a virtual host on Tomcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.