Tomcat core components and Server.xml configuration explanation

Source: Internet
Author: User
Tags tomcat server
<!--Tomcat's core components: Server Service Connector Engine Host context;
  Other components can be grouped into inline components (that is, embedded in these components)
-->
<!--each element tag corresponds to one component of Tomcat, which controls the component through element configuration-->
The Server.xml configuration file structure is as follows:
<ServerPort= "8005"shutdown= "SHUTDOWN"> <Servicename= "Catalina"> <ConnectorPort= "8080"Protocol= "http/1.1" ConnectionTimeout= "20000" Redirectport= "8443"/> <ConnectorPort= "8009"Protocol= "ajp/1.3"Redirectport= "8443"/> <Enginename= "Catalina"Defaulthost= "localhost"> <Hostname= "localhost"AppBase= "WebApps"Xmlbase= "Conf/catalina/localhost/web.xml" Unpackwars= "true"Autodeploy= "true"Deployonstartup= "true"> </Host> <Hostname= "Www.baidu.com"AppBase= "Web-baidu" Unpackwars= "true"Autodeploy= "true"> </Host> <Hostname= "Www.sina.com"AppBase= "Web-sina" Unpackwars= "true"Autodeploy= "true"> < ContextDocBase="" Path="" reloadable=""> </ Context> <ValveClassName= "Org.apache.catalina.valves.AccessLogValve"Directory= "Logs" prefix= "Localhost_access_log"suffix= ". txt"  Pattern= "%h%l%u%t&quot;%r&quot;%s%b "/> </Host> </Engine> </Service> </Server>

?XML version= ' 1.0 'encoding= ' Utf-8 '?> <!--Tomcat's core components: Server Service Connector Engine Host context; Other components can be grouped into inline components (that is, embedded in these components)--> <!--each element tag corresponds to a component of Tomcat, which implements control of the component through element configuration,--> <!--server: Top level elements, Represents the entire Tomcat container, must be unique, the root element of the entire configuration file: Provide an interface for clients to access the service collection inside, while maintaining the lifecycle of all services it contains (including how to initialize, how to end the service, How to find the service that the client will access, etc. shutdown: Indicates the command to shut down the server; Port: Indicates the port number on which the server receives the shutdown directive, set to-1 to disable the port--> <ServerPort= "8005"shutdown= "SHUTDOWN"> <ListenerClassName= "Org.apache.catalina.startup.VersionLoggerListener"/> <ListenerClassName= "Org.apache.catalina.core.AprLifecycleListener"Sslengine= "On"/> <ListenerClassName= "Org.apache.catalina.core.JreMemoryLeakPreventionListener"/> <ListenerClassName= "Org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/> <ListenerClassName= "Org.apache.catalina.core.ThreadLocalLeakPreventionListener"/> <globalnamingresources> <Resourcename= "Userdatabase"Auth= "Container" type= "Org.apache.catalina.UserDatabase" Description= "User database" can be updated and saved " Factory= "Org.apache.catalina.users.MemoryUserDatabaseFactory" Pathname= "Conf/tomcat-users.xml"/> </globalnamingresources> <!--service: A top-level element that can have one or more elements, including a engine element and a group of connector elements: assemble connector and engine together, provide services externally; Can contain multiple connector, but
     There can be only one engine; The function of connector is to receive the client request, engine to process the received request;--> <Servicename= "Catalina"> <!--service name is Catalina, or other service configured for Tomcat, the listening port is different--> <!--Connector: connectors, sending requests on behalf of external clients to specific SE
                Rvice interface, which is also the interface that external clients receive responses from a particular service; function: Receive connection requests, create request and response objects for exchanging data with the requester, and then allocate lines Chengyang engine to process the request.
           The resulting request and response objects are passed to engine. Port: Client Request Service port number protocol: Requested protocol ConnectionTimeout: timeout for connection redirectport: Indicates when HTTPS is forced When the request is HTTP, redirect the connection to Port 8443 extra: In fact, even in a formal production environment, it is often configured with 8080 ports rather than 80 ports; because in practice, Tomcat is rarely opened to the outside world to receive
        Request, but adds a layer of proxy server (such as Nginx) between Tomcat and client for request forwarding, load balancing, processing of static files, etc. tomcat and nginx are generally in the same LAN, so generally do not use 80 ports. --> <ConnectorPort= "8080"Protocol= "http/1.1" ConnectionTimeout= "20000" Redirectport= "8443"/> <!--Configure this connector to represent clients using the AJP protocol to access Tomcat via the 8009 port number, and the AJP protocol is responsible for establishing connections with other HTTP servers (such as Apache), and in putting Tomcat with its
           When he is integrated with HTTP server, this connection is needed. Tomcat and other server integrations are used because Tomcat can be used as a servlet/jsp container, but it is slower to handle static resources and has less performance than an HTTP server such as Apache, IIS, and so often integrates Tomcat with Apache, to MCAT as a servlet container, Apache handles static resources, where the AJP protocol is responsible for the connection between the--> <ConnectorPort= "8009"Protocol= "ajp/1.3"Redirectport= "8443"/> <!--containers: (Engine, Host, context), the role of the container is to handle the connector received in the request, and generate corresponding response Engine Host context three are containers, but not parallel
        Relationship, but a parent-child (inclusive) relationship, where engine contains the host,host containing the context. Engine: Can process all requests in the service; Host: can handle all requests sent to a particular virtual host; context: can handle all requests for a particular Web application;--> <!-
             -Engine has and only one in service and is responsible for processing requests, which receive requests and processes from one or more connector, and return the completed response to the connector, which is eventually passed on to the client. Name: for log and error messages; Defaulthost: The default host name is established, and the specified host name does not exist when the request is sent to the local computer, and is treated with its designated host; therefore, the value of Defaulthost
        Must match the Name property value of a host under the engine. --> <Enginename= "Catalina"Defaulthost= "localhost"> <RealmClassName= "Org.apache.catalina.realm.LockOutRealm"> <RealmClassName= "Org.apache.catalina.realm.UserDatabaseRealm" resourcename= "Userdatabase"/> </Realm> <!--host is a engine, engine can have one or more host components, each host representing a virtual host in engine but at least one, and one (with and only one
             Name property value must match the engine Name property.
             Function: Run multiple Web applications (a context represents a Web application) and be responsible for installing, expanding, starting, and ending each Web application. A host corresponds to a network name entity in the server (such as www.baidu.com, or IP address 123.12.34.22), in order for the user to connect to the Tomcat server via the network name, the name should be registered on the DNS server; The client usually uses the host name to Identify the server to which they want to connect the host name is included in the HTTP request header in, Tomcat extracts the hostname from the HTTP request header, looks for a matching host to send the resource to find the request, if there is no match, the request will be sent to the default host, so the default host can not need
     
                 To register on the DNS server. Here for easy explanation, I will configure three host, including: appbase: The file directory that represents the resource; Unpackwars: Represents whether the war file that represents the Web application is unzipped (the students who have developed a Web project here should know that the department
             When acting tomcat, the resource is placed under the war package for true to run the Web application through the unpacked file structure, and for false to run the Web application directly using the war file. Autodeploy: Automatic deployment (Periodic check during run), that is, if updates are automatically checked and deployed after the resource is updated, the resource deployment is automatically updated for true, Deployonstartup : Whether to deploy automatically (when Tomcat is started), that is, if you check for new Web applications or if there is an update to the Web application, triggering the deployment as true represents an automatic update of the resource deployment, both of which are checked for appbase and xmlbase two The resources under the directory areNo change xmlbase: The default directory is conf/engine_name/host_name, such as the profile is Conf/catalina/localhost, not configured to use the default-->
            <!--the name of the host matches the defaulthost of engine, and if no host is specified in the request sent to the native, the host is entered by default (WebApps directory) for the requested resource --> <Hostname= "localhost"AppBase= "WebApps"Xmlbase= "Conf/catalina/localhost/web.xml" Unpackwars= "true"Autodeploy= "true"Deployonstartup= "true"> </Host> <!--If you specify host as "Www.baidu.com" in a request sent to this computer, go to the host (Web-baidu directory) to find the requested resource--&
            Gt <Hostname= "Www.baidu.com"AppBase

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.