1. 在一个Tomcat下配置多个服务,用不同的端口号
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector protocol="AJP/1.3"
port="8008"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
=================================================================================
<Service name="Catalina">
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector protocol="AJP/1.3"
port="8009"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps1"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
请注意protocol="AJP/1.3"中port端口配置
以上两个个service,发布的路径不同,项目分别发布在webapps、webapps1下,
访问不同的项目的方法:
http://localhost:8080/项目名称1
http://localhost:8081/项目名称2
2. 修改项目访问路径
- 配置介绍
<Host name="localhost" appBase="/root/webfile/webapps" unpackWARs="true" autoDeploy="true">
name是虚拟主机名,对应目录 /conf /Catalina /localhost
unpackWARs 为是否自动解压war文件,如果设置为true,表示把war文件先展开再运行。如果为false则直接运行war文件
autoDeploy,默认为true,表示如果有新的WEB应用放入appBase并且Tomcat在运行的情况下,自动载入应用
- 修改默认访问路径
(1)第一种方式
可以直接把项目名称修改为ROOT,放在 tomcat/webapps/目录即可
此时,访问项目路径为:http://localhost:8081/
(2)第二种方式
<Host name="localhost" appBase="E:\softsware\apache-tomcat-8.5.55-windows-x64\apache-tomcat-8.5.55\webapps1"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="E:\softsware\apache-tomcat-8.5.55-windows-x64\apache-tomcat-8.5.55\webapps1\demo" reloadable="true"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
path代表用浏览器访问的时候的的路径,如http://localhost:8080/web来访问path=”/web”
docBase为你的项目的路径,这里同样既可以用相对路径,也可以用绝对路径。设置好了之后就会把项目自动映射到ROOT
reloadable,如果这个属性设为true,tomcat服务器在运行状态下会监视在WEB-INF/classes和WEB-INF/lib目录下class文件的改动,如果监测到有class文件被更新的,服务器会自动重新加载Web应用
附图:
3. 配置context后项目启动多次
将appBase=“webapps"置为appBase=”",docBase="myapp"置为docBase=“E:\softsware\apache-tomcat-8.5.55-windows-x64\apache-tomcat-8.5.55\webapps1\demo”。
》》》博主长期更新学习心得,推荐点赞关注!!!
》》》若有错误之处,请在评论区留言,谢谢!!!