Tomcat build a name-based virtual hosting is in fact achieved the same Tomcat deploy multiple projects (website / application). Port can use the same or different.
. (1) there is Tomcat configuration file in tomcat's conf folder:
catalina.policy is Tomcat security configuration file, Tomcat non-secure mode of operation, if you need to use safe mode, you need to add -security command line parameter in the startup default.
Catalina is catalina.properties configuration files, there are security settings, setting a class loader, class settings need to scan, the character buffer is provided four blocks.
Tomcat context.xml is separated from the 6.0 server.xml out, provided Tomcat data source, mainly used to connect a database that can be dynamically loaded Tomcat.
jaspic-providers.xml: Tomcat implements JASPIC 1.1 Maintenance Release B standard, and verified by the configuration file integrate third-party JASPIC identity.
jaspic-providers.xsd defined jaspic-providers.xml used to label.
logging.properties is the Tomcat log configuration file.
server.xml is Tomcat's main configuration file, set the parameters related services (such as paths, ports), the file does not support hot update, every time you need to restart the Tomcat server after the changes are complete to take effect.
tomcat-users.xml is Tomcat user profile information is used in the Tomcat Manager.
tomcat-users.xsd defines tomcat-users.xml used to label.
All Web project web.xml is the default configuration file.
(2) using the same Tomcat, the same port, the deployment of multiple projects
1) modify the configuration file server.xml
[youxi1 the root @ ~] # Vim /usr/local/tomcat8.5/conf/server.xml // add test <Host> tag label behind existing <Host>. To the original label and tag are in the same range (<Engine> tag inside) <the Host name = "www.youxi1.com" the appBase = "/ var / WWW"> <path the Context = "" the docBase = "/ var / WWW / youxi1 "/> </ the Host> <the Host name =" www.youxi2.com "the appBase =" / var / WWW "> <path the Context =" "the docBase =" / var / WWW / youxi2 "/> </ Host>
Description: <Host> tag to specify the domain name; appBase specify the base directory of the project (publishing directory), can be an absolute path, or a relative path, relative path is based on the Tomcat installation directory.
<Context> tag in the path specified virtual directory domain, if it is empty representatives is /, if path = "test", then when access is [domain name | [IP: port]] / test; docBase specify the actual storage directory, you can an absolute path or a relative path and relative path based on the parameters of the current appBase <Host> tag.
2) Create a test page
[root@youxi1 ~]# mkdir -p /var/www/{youxi1,youxi2} [root@youxi1 ~]# echo "This is One." > /var/www/youxi1/index.html [root@youxi1 ~]# echo "This is Two." > /var/www/youxi2/index.html
If you wrote a startup script, you can use the startup script to restart. If you did not write the startup script, it is recommended kill off tomcat restart, as follows:
[root @ youxi1 ~] # ps aux | grep "/usr/local/tomcat8.5" // This is to specify the Tomcat want to restart, prevent multiple Tomcat running root 1833 98.0 5.8 2256888 57996 pts / 0 11:44 0:02 /usr/local/jdk1.8.0_191/bin/java -Djava.util.logging.config.file = SL / usr / local / tomcat8.5 / the conf / the logging.properties -Djava.util. = 2048 = org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize logging.manager -Djava.protocol.handler.pkgs = org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK = 0027 - = -classpath /usr/local/tomcat8.5/bin/bootstrap.jar:/usr/local/tomcat8.5/bin/tomcat-juli.jar Dignore.endorsed.dirs -Dcatalina.base = / usr / local / tomcat8 .5 -Dcatalina.home = / usr / local / tomcat8.5 -Djava.io.tmpdir = / usr / local / tomcat8.5 / temp org.apache.catalina.startup.Bootstrap start 0.0 0.0 112 720 992 1846 the root PTS / 0 + 11:45 0:00 grep R & lt --color = Auto /usr/local/tomcat8.5 [root @ youxi1 ~] # 1833 // kill the kill -9 [youxi1 the root @ ~] # PS AUX | grep "/usr/local/tomcat8.5 "// see if kill the root 992 1881 0.0 0.0 112.72 thousand PTS / 0 + 11:45 0:00 grep R & lt --color = Auto /usr/local/tomcat8.5 [youxi1 the root @ ~] # / usr / local / tomcat8 .5 / bin / startup.sh // invoke the startup script the Using CATALINA_BASE: /usr/local/tomcat8.5 the Using CATALINA_HOME: /usr/local/tomcat8.5 the Using CATALINA_TMPDIR: /usr/local/tomcat8.5/temp the Using JRE_HOME : /usr/local/jdk1.8.0_191 the Using the CLASSPATH: /usr/local/tomcat8.5/bin/bootstrap.jar:/usr/local/tomcat8.5/bin/tomcat-juli.jar Tomcat Started. [root @ youxi1 ~] # ps aux | grep "/usr/local/tomcat8.5" // see if open root 1891 93.0 5.8 2257916 58068 pts/0 Sl 11:45 0:02 /usr/local/jdk1.8.0_191/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8.5/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat8.5/bin/bootstrap.jar:/usr/local/tomcat8.5/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8.5 -Dcatalina.home=/usr/local/tomcat8.5 -Djava.io.tmpdir=/usr/local/tomcat8.5/temp org.apache.catalina.startup.Bootstrap start root 1905 0.0 0.0 112720 992 pts/0 R+ 11:45 0:00 grep --color=auto /usr/local/tomcat8.5
3) Testing
Modify the hosts file on Windows, the analog domain name resolution. This step is the actual DNS server to resolve domain names. Address file: C: \ Windows \ System32 \ the Drivers \ etc \ hosts . Add two lines
192.168.5.101 www.youxi1.com 192.168.5.101 www.youxi2.com
Use your browser to view
(3) Using the same Tomcat, different ports, deploying multiple projects
1) modify the configuration file server.xml
[youxi1 the root @ ~] # Vim /usr/local/tomcat8.5/conf/server.xml // first found in the <service> tag <Connector> tag, copy and paste the bottom, and then modify the value of the parameter port. <Connector Port = "8081" Protocol = "the HTTP / 1.1" connectionTimeout = "20000" the redirectPort = "8443" /> <Connector Port = "8082" Protocol = "the HTTP / 1.1" connectionTimeout = "20000" the redirectPort = "8443" /> // then this <service> within <Engine> tag in the tag, find the <Host> tag, add the following line <Host name = "www.youxi3.com" appBase = "/ var / www" port = " 8081 "> <path the Context =" "the docBase =" / var / WWW / youxi3 "/> <
<Host> tag compared to the same port configuration <Host> tag, one more port parameters port.
2) Create a test page
[root@youxi1 ~]# mkdir -p /var/www/youxi{3,4} [root@youxi1 ~]# echo "This is Three" > /var/www/youxi3/index.html [root@youxi1 ~]# echo "This is Four" > /var/www/youxi4/index.html
Restart tomcat
[root@youxi1 ~]# !ps ps aux | grep "/usr/local/tomcat8.5" root 2345 0.9 9.8 2325048 98620 ? Sl 12:11 0:11 /usr/local/jdk1.8.0_191/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8.5/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat8.5/bin/bootstrap.jar:/usr/local/tomcat8.5/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8.5 -Dcatalina.home=/usr/local/tomcat8.5 -Djava.io.tmpdir=/usr/local/tomcat8.5/temp org.apache.catalina.startup.Bootstrap start root 2546 0.0 0.0 112720 992 pts/0 R+ 12:32 0:00 grep --color=auto /usr/local/tomcat8.5 [root@youxi1 ~]# kill -9 2345 [root@youxi1 ~]# !ps ps aux | grep "/usr/local/tomcat8.5" root 2549 0.0 0.0 112720 992 pts/0 R+ 12:32 0:00 grep --color=auto /usr/local/tomcat8.5 [root@youxi1 ~]# /usr/local/tomcat8.5/bin/startup.sh Using CATALINA_BASE: /usr/local/tomcat8.5 Using CATALINA_HOME: /usr/local/tomcat8.5 Using CATALINA_TMPDIR: /usr/local/tomcat8.5/temp Using JRE_HOME: /usr/local/jdk1.8.0_191 Using CLASSPATH: /usr/local/tomcat8.5/bin/bootstrap.jar:/usr/local/tomcat8.5/bin/tomcat-juli.jar Tomcat started. [root@youxi1 ~]# !ps ps aux | grep "/usr/local/tomcat8.5" root 2559 91.6 5.8 2255860 58460 pts/0 Sl 12:32 0:02 /usr/local/jdk1.8.0_191/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8.5/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat8.5/bin/bootstrap.jar:/usr/local/tomcat8.5/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8.5 -Dcatalina.home=/usr/local/tomcat8.5 -Djava.io.tmpdir=/usr/local/tomcat8.5/temp org.apache.catalina.startup.Bootstrap start root 2572 0.0 0.0 112720 992 pts/0 S+ 12:32 0:00 grep --color=auto /usr/local/tomcat8.5
If you turn on the firewall need to add the port number
[root@youxi1 ~]# systemctl start firewalld.service [root@youxi1 ~]# firewall-cmd --permanent --zone=public --add-port={8081,8082}/tcp success [root@youxi1 ~]# firewall-cmd --reload success [root@youxi1 ~]# firewall-cmd --permanent --zone=public --list-ports 8080/tcp 8081/tcp 8082/tcp
3) Testing
Windows modifies the hosts file, address: C: \ Windows \ System32 \ the Drivers \ etc \ hosts . Add two lines:
192.168.5.101 www.youxi3.com 192.168.5.101 www.youxi4.com
On the Windows Explorer View
Note: You can also copy the entire <service> tag, modify.
Reference: https://blog.csdn.net/dreamstar613/article/details/75282962/