server.xml configuration in Tomcat
After we have developed a Web application, we need to publish the application to webserver so that other users can access it. In the field of Java Web Development, we typically use Tomcat as our web server for testing or formal deployment.
Typically, we package the Web application in the war format and then copy it to Tomcat's WebApp directory to publish it, under normal circumstances, Tomcat automatically extracts the war file and generates the corresponding directory, and dynamically creates the corresponding context path for the Web application in memory. For example, our war file is Sample.war, then the unpacked directory is Sample directory, in memory dynamically created by the context path is/sample. The default behavior in the development phase is acceptable, but in the case of a formal deployment, we usually need to modify the application's context path to suit our needs.
If we want users to simply enter the domain name to access our sample application, we need to modify the Tomcat settings. There are two ways to set up a context path, one is to modify the {Tomcat_home}/conf/server.xml file, and the other is to create a context fragment file in the WebApps directory. We introduce the first approach here.
<?xml version= "1.0" encoding= "UTF-8"?> <Server> <listener classname= "Org.apache.catalina.mbeans.Glob Alresourceslifecyclelistener "/> <listener classname=" Org.apache.catalina.storeconfig.StoreConfigLifecycleListener "/> <listener classname=" Org.apache.catalina.mbeans.ServerLifecycleListener "/> <GlobalNamingResources> <environment N
Ame= "Simplevalue" type= "Java.lang.Integer" "value="/> <resource "auth=" description= "User database" can be updated and saved "name=" Userdatabase "type=" Org.apache.catali Na. Userdatabase "Pathname=" Conf/tomcat-users.xml "factory=" Org.apache.catalina.users.MemoryUserDatabaseFactor Y "/> </GlobalNamingResources> <service name=" Catalina "> <connector port=
"8080" redirectport= "8443" minsparethreads= "connectiontimeout=" "20000" maxsparethreads= "maxthreads=" maxhttpheadersize= "8192" > </Connector> <connector port= "8009" redirectport= "8443" protocol= "ajp/1.3" > </connector > <engine defaulthost= "localhost" name= "Catalina" > <realm classname= "Org.apa"
Che.catalina.realm.UserDatabaseRealm "/>
Introduction to Server.xml Configuration
Here is the basic configuration information in this file, more specific configuration information see Tomcat's documentation
Server
PORT specifies the ports that are responsible for listening for requests to shut down Tomcat
SHUTDOWN Specifies the command string to be sent to the port
Service
Name to specify service names
Connector (indicates the connection between client and service):
PORT Specifies the port number to be created on the server side and listens for requests from the client on this fracture surface
Minprocessors number of threads created at server startup to process requests
Maxprocessors the maximum number of threads that can be created for processing requests
Enablelookups If True, you can obtain the actual hostname of the remote client by calling Request.getremotehost (), or false, and return its IP address instead of the DNS query
REDIRECTPORT specifies that the server is processing an HTTP request and receives a port number that is redirected after an SSL transfer request
ACCEPTCOUNT Specifies the number of requests that can be placed in the processing queue when all available processing requests are used, and requests that exceed this number will not be processed
ConnectionTimeout specify the number of times to timeout in milliseconds
Engine (represents a request processor in a specified service, receiving and processing requests from connector):
DEFAULTHOST Specifies the host name of the default processing request, which is at least the same as the Name property value of one of the host elements
Context (representing a Web application, usually a war file, and specific information about war, see servlet specification):
DocBase the path of the application or the path to which the war file resides, specifies the file path of the Web application, either given an absolute path, or a relative path to the corresponding AppBase property, and if the Web application uses an Open directory structure, specifies the root directory of the Web application. If the Web application is a war file, specify the path to the war file.
Path represents the prefix of the URL for this Web application, so the URL for the request is http://localhost:8080/path/****
Reloadable This property is important, and if true, Tomcat automatically detects changes in the application's/web-inf/lib and/web-inf/classes directories, automatically loading new applications, We can change the application without going back to Tomcat, and if this property is set to true,tomcat the server will monitor changes to the class file in the Web-inf/classes and Web-inf/lib directories. The server automatically reloads the Web application if a class file is detected to be updated.
Host (represents a virtual host):
Name Specifies host name
AppBase Application Base directory, that is, the directory where the application resides
Unpackwars if True, Tomcat automatically extracts the war file, otherwise it does not understand the pressure and runs the application directly from the war file
Logger (for logs, debugging, and error messages):
CLASSNAME specifies the class name used by Logger, which must implement the Org.apache.catalina.Logger interface
prefix specifies the prefix of the log file
suffix specifies the suffix of the log file
Timestamp if true, the log file name is added to the time, as in the following example: Localhost_log.2001-10-04.txt
Realm (a database that holds user names, passwords, and role):
CLASSNAME specifies the class name used by realm, which must implement the Org.apache.catalina.Realm interface
Valve (features similar to logger, whose prefix and suffix properties are interpreted as in logger):
CLASSNAME specifies the class name used by valve, such as the use of Org.apache.catalina.valves.AccessLogValve classes to record access information for an application
directory specifies where log files are stored
Pattern has two values, common way to record the remote host name or IP address, username, date, the first line of the requested string, HTTP response code, the number of bytes sent. Combined is more than the common way to record
Attention:
In the default server.xml, the realm element sets only one classname property, but this file also contains several examples of validation connected to the database through JDBC (commented out) and we can implement container security management through realm elements (Container Managed security).
There are also elements, such as Parameter,loader, where you can get information about these elements through Tomcat's documentation.