2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Table of contents
Features and functions of tomcat
The role of the tomcat directory
Configure Tomcat's virtual host
Tomcat, like PHP, is used to process dynamic pages. Tomcat can also be used as a web application server, and it is open source.
It processes files ending with .jsp. tomcat is a program written in java and runs java web applications.
1. Servlet container: executes Java servlet, which is a Java program on the server side, used to process client HTTP requests and respond
2.jsp container: javascript page, which is a dynamic page technology that can embed java code in html page
3. It is also an http server
4. Tomcat is a lightweight dynamic page processing program and is not suitable for high-concurrency scenarios
It mainly optimizes tomcat itself as well as the system's kernel and jvm.
Servlet: It is a key component for developing web applications in Java. Functions: Process http requests, generate dynamic content and respond to client requests, process Java business logic, and perform session management. It can maintain user status information, synchronize shopping carts, user logins, etc. It can also forward nginx dynamic requests to the database.
jsp: The interface of the web application, which is implemented in Java. It is a file ending with .jsp (index.jsp)
Connector: Responsible for receiving and responding to external requests. It is a hub for Tomcat to communicate with the client. It listens to the port to receive external requests. Its default port is 8080. After receiving the request, it passes it to other components for processing. After processing is completed, it returns to the connector and responds to the client.
Container: responsible for processing business logic, it consists of four functions: engine host context wrapper
Engine: can be used to manage multiple virtual hosts. A service can only have one engine.
Host: A host is a host, which can also be called a site. By configuring the host, you can add multiple sites.
context: A context represents a web application
Wrapper: It is a wrapper that handles the lowest level logic
Service: Provides external services, including connectors and containers
Tomcat can have multiple services. Each service is independent of each other.
1. Install Java first
2. Add a configuration file to identify java
vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$PATH
3. Restart configuration source /etc/profile.d/java.sh
4. Unzip tomcat
tar -xf apache-tomcat-9.0.16.tar.gz
mv apache-tomcat-9.0.16 tomcat
mv tomcat /usr/local
5. Start tomcat
Then run ./startup.sh
Check the port and start netstat -antp | grep 8080
Visit 192.168.233.40:8080
1. .bin files that store startup and shutdown scripts for Tomcat. startup.sh shutdown.sh
2. .conf stores the main configuration file of tomcat, server.xml main configuration file
3. context.xml: default configuration information of host
4. tomcat-user.xml: related information of the authentication user and password when logging in. The manager file must be authorized to modify before it can be opened
5. lib: jar package required by tomcat when running (usually not changed)
6. logs: log files,catalina.outMain log file
7. temp: stores files generated when tomcat is running
8. webapps: A directory for deploying web applications, similar to html in nginx
1. cd /usr/local/tomcat/webapps/manager/META-INF
2. vim context.xml
3. In conf, tomcat-users.xml, add the account password
cd /usr/local/tomcat/
cd conf/
vim tomcat-users.xml
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
4.cd bin/
./stutdown.sh
./startup.sh
netstat -antp | grep 8080
Visit 192.168.233.40:8080 and click tomcat. Enter the account and password tomcat.
vim server.xml
Delete line 147 and add two sites
<Host name="www.xy102.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/usr/local/tomcat/webapps/xy102" path="" reloadable="true" />
</Host>
<Host name="www.benet.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/usr/local/tomcat/webapps/benet" path="" reloadable="true" />
</Host>
vim /etc/hosts mapping
Achieve Results