First, Apache-tomcat way:
Configuration file: Server.xml
Main Configuration items:
1. Server:
<port= "8005" shutdown= "shutdown"></ Server>
Specify port 8005 to listen for requests to shut down Tomcat.
2, Connector: A total of two, define the connection between the client and the server. After the client initiates the request, it is forwarded to the engine for processing, and then the response is returned to the client.
The first listener 80 port (if only Tomcat, no Apache, here is listening to 8080 ports), directly receive requests from the client browser. If SSL (HTTPS) is requested, Port 8443 is used.
<port= " protocol"= "http/1.1" connectiontimeout = "20000" redirectport= "8443"/>
The second listens on Port 8009, receiving HTTP requests forwarded through other webserver (such as Apache).
<port= "8009" protocol= "ajp/1.3" redirectport= " 8443 "/>
3. Engine: Define Virtual Host
The host defines the virtual hostname and AppBase defines the application storage directory.
<name= "localhost" appBase= "WebApps" Unpackwars= "true" autodeploy= "true">
Multiple hosts can be defined in the engine, and when the engine receives an HTTP request, it is matched to a virtual host, which is processed by the virtual host. If there is no match to a virtual host, the request is given to the default set of virtual hosts for processing.
When configured above, for example the application directory is: Webapps/hello/index ..., the access URL is Localhost/hello.
Second, the process of APACHE-TOMCAT processing HTTP requests:
1, the client directly requests 80/8080 port (or by 8009 port to receive the request forwarded by other webserver such as Apache), connector receives the client request.
2, connector the HTTP request to the engine.
3, the engine receives the request, matches to the corresponding host, the request is handed over to the host processing.
4. Host handles the request and returns the result on the original path.
5, connector received the processing results, returned to the client or other webserver.
How Tomcat works