Http://www.blogjava.net/WshmAndLily/articles/143450.html
1. Set the Domain Name of the local host
Hosts is a system file without an extension. It can be opened using notepad and other tools. Its function is to associate some common website domain names with their corresponding IP addresses to a "Database ", when you enter a URL to log on to the browser, the system will first automatically find the corresponding IP address from the hosts file. Once found, the system will immediately open the corresponding webpage, if no IP address is found, the system submits the website address to the DNS domain name resolution server for IP Address Resolution.
By modifying a hosts file on the local host, you can map the IP address to the local domain name, so that you can access it through the local domain name when debugging the JSP project locally.
Hosts files are stored in the system directory c: \ windows \ system32 \ drivers \ etc \. This directory is not easy to remember. If you need to modify this file frequently, it is not very convenient to find it, you can create a batch hosts. BAT file, open it in a text editor, write content Explorer "C: \ windows \ system32 \ drivers \ etc", save and exit, you can put this hosts. the bat file is placed on the desktop. You can double-click it to open the directory where the hosts file is located. You can also set the hosts. put the bat file in c: \ windows. In this way, you only need to click "start"> "run", enter hosts, and press enter to open the directory where the hosts file is located, in addition, you can enter hosts in the command line to open the directory where the hosts file is located.
Find the hosts file and open it in a text editor. By default, there is only one ing in the hosts file:
127.0.0.1 localhost
Add another ing in this format:
XXX. XXX www.xxxx.com
Save and exit. At this time, the local IP address 202.112.113.171 has been mapped to the local domain name www.xxxx.com.
2. server. xml configuration overview
The basic configuration information of server. xml. For more detailed configuration information, see the Tomcat documentation.
Server:
Port specifies a port, which is used to listen for requests to disable tomcat.
Shutdown specifies the command string sent to the port
Service:
Name indicates the service name.
Connector (indicating the connection between the client and the Service ):
Port: Specifies the port number to be created on the server, and listens to requests from the client on this fracture.
Number of threads created to process requests when the minprocessors server is started
Maxprocessors: Maximum number of threads that can be created to process requests
If enablelookups is true, you can call request. getremotehost () to query the DNS to obtain the actual Host Name of the remote client. If it is false, no DNS query is performed, but the IP address is returned.
Redirectport specifies the port number to be redirected after receiving an SSL transfer request when the server is processing an HTTP request
Acceptcount indicates the number of requests that can be placed in the processing queue when the number of threads that can be used to process requests is used. requests exceeding this number will not be processed.
Connectiontimeout specifies the timeout time (in milliseconds)
Engine (indicates the request processing machine in the specified service to receive and process requests from ctor ):
Defaulthost specifies the default host name for processing requests. It must be at least
The value of name attribute is the same.
Context (indicating a web application Program , Usually a war file. For details about war, see the servlet specification ):
Docbase application path or war file storage path
Path indicates the prefix of the URL of the Web application. The requested URL is http: // localhost: 8080/path /****
Reloadable this property is very important, if it is true, Tomcat will automatically detect changes to the application's/WEB-INF/lib and/WEB-INF/classes directory, automatically load the new application, you can change the application without restarting tomcat.
Host (a virtual host ):
Name specifies the Host Name
The basic directory of the appbase application, that is, the directory where the application is stored.
If unpackwars is true, Tomcat automatically decompress the war file. Otherwise, the application runs directly from the war file.
Logger (indicating logs, debugging, and error messages ):
Classname specifies the class name used by logger. This class must be implemented
Org. Apache. Catalina. logger interface
Prefix specifies the prefix of the log file
Suffix specifies the suffix of the log file
If timestamp is true, time is added to the log file name, for example: localhost_log.2001-10-04.txt
Realm (indicates the database that stores the username, password, and role ):
Classname specifies the class name used by realm. This class must implement the org. Apache. Catalina. realm Interface
Valve (similar to logger, its prefix and suffix attributes are interpreted as the same as those in logger ):
Classname specifies the class name used by valve. For example, the org. Apache. Catalina. Valves. accesslogvalve class can be used to record application access information. Directory specifies the location where log files are stored.
Pattern has two values. The common method records the remote host name or IP address, user name, date, the string of the first line request, and the HTTP response. Code The number of bytes sent. The combined method has more values than the common method.
3. Configure Virtual Hosts)
The "host" element in server. xml must be modified only when you set the virtual host. A vm is a mechanism that serves multiple domain names on a Web server. For each domain name, it seems that the entire host is exclusive. . In fact, most small business websites use virtual hosts. This is mainly because virtual hosts can directly connect to the Internet and provide corresponding bandwidth to ensure reasonable access response speed, in addition, the VM can provide a stable fixed IP address.
A name-based virtual host can be created on any Web server by creating an IP address alias on the Domain Name Server (DNS, the Web server is also notified to distribute requests to different domain names to the corresponding web directory. To use a VM in Tomcat, you need to set DNS or host data. Set content in server. XML as follows:
< Server Port = "8005" Shutdown = "Shutdown" Debug = "0" > < Service Name = "Tomcat-standalone" > < Connector Classname = "Org. Apache. Coyote. tomcat4.coyoteconne" Port = "80" Minprocessors = "5" Maxprocessors ="75" Enablelookups = "True" Redirectport = "8443" /> < Connector Classname = "Org. Apache. Coyote. tomcat4.coyoteconne" Port = "8443" Minprocessors = "5" Maxprocessors ="75" Acceptcount = "10" Debug = "0" Scheme = "HTTPS" Secure = "True" /> < Factory Classname = "Org. Apache. Coyote. tomcat4.coyoteserversocketfactory" Clientauth ="False" Protocol = "TLS" /> </ Connector > < Engine Name = "Standalone" Defaulthost = "Localhost" Debug = "0" > <! -- This host is the default host --> < Host Name = "Localhost" Debug = "0" Appbase = "Webapps" Unpackwars = "True" Autodeploy = "True" > < Context Path = "" Docbase = "Root" Debug = "0" /> < Context Path = "/Orders" Docbase = "/Orders" Debug = "0" Reloadable = "True" Crosscontext = "True" > </ Context > </ Host > <! -- This host is the first "virtual host": http://www.yujiaxin.com --> < Host Name ="Www.yujiaxin.com" Appbase = "Webapps" Unpackwars = "True" Autodeploy = "True" Xmlvalidation = "False" Xmlnamespaceaware = "False" > < Context Docbase ="Jspwebsite" Path = "" Reloadable = "True" /> </ Host > </ Engine > </ Service > </ Server >
Tomcat's server. xml file contains only one virtual host in the initial state, but it is easy to expand to support multiple virtual hosts. To add a virtual host, you only need to add the complete host tag. Each host element must contain one or more context elements. The contained context element must have a default context. The display path of this default context should be blank (for example, path = "").