修改tomcat/conf目录里面server.xml文件
例如下面这样新增一个8081端口,设置下appbase目录,这样就可以用一个tomcat监听多个端口,每个端口都可以放应用了。我这样新增下面这个配置以后,tomcat就监听了2个端口(8080,8081)
webapps目录和webapps1目录的应用都会启动,可以根据不同的端口进行访问里面的应用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<? xml version = "1.0" encoding = "utf-8" ?> < server port = "8005" shutdown = "shutdown" > < listener classname = "org.apache.catalina.startup.versionloggerlistener" /> < listener classname = "org.apache.catalina.core.aprlifecyclelistener" sslengine = "on" /> < listener classname = "org.apache.catalina.core.jrememoryleakpreventionlistener" /> < listener classname = "org.apache.catalina.mbeans.globalresourceslifecyclelistener" /> < listener classname = "org.apache.catalina.core.threadlocalleakpreventionlistener" /> < globalnamingresources > < resource name = "userdatabase" auth = "container" type = "org.apache.catalina.userdatabase" description = "user database that can be updated and saved" factory = "org.apache.catalina.users.memoryuserdatabasefactory" pathname = "conf/tomcat-users.xml" /> </ globalnamingresources > < service name = "catalina" > < connector port = "8080" protocol = "http/1.1" connectiontimeout = "20000" redirectport = "8443" /> < connector port = "8009" protocol = "ajp/1.3" redirectport = "8443" /> < engine name = "catalina" defaulthost = "localhost" > < realm classname = "org.apache.catalina.realm.lockoutrealm" > < 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 = "catalina2" > < connector port = "8081" protocol = "http/1.1" connectiontimeout = "20000" redirectport = "8445" /> < connector port = "8010" protocol = "ajp/1.3" redirectport = "8445" /> < engine name = "catalina" defaulthost = "localhost" > < realm classname = "org.apache.catalina.realm.lockoutrealm" > < realm classname = "org.apache.catalina.realm.userdatabaserealm" resourcename = "userdatabase" /> </ realm > < host name = "localhost" appbase = "webapps2" 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 > </ server > |
ok
把项目war包改名为root放进appbase属性指定的路径下启动服务即可。
附:tomcat端口说明:
1. 采用记事本打开tomcat安装目录下的conf文件夹下的server.xml文件。
2. 在server.xml文件中找到以下代码:
(1)<connector port="8080"protocol="http/1.1"connectiontimeout="20000" redirectport="8443"/>
此连接器是负责建立http连接。再通过浏览器访问tomcat服务器的web应用时使用的就是这个端口,如果此端口被占用可将其修改一个未被占用的端口,例如 将上面代码中的port="8080"修改为port="8081",即可将tomcat的默认端口设置为8081。在修改端口时,应避免与公用端口冲突。建议采用默认的8080端口,不要修改,除非8080端口被其他程序所占用。
(2) <server port="8005" shutdown="shutdown">
8005端口是用来关闭tomcat服务的端口,如果此端口被占用,可在配置文件中将8005改成其他端口
(3)<connector port="8009" protocol="ajp/1.3" redirectport="8443" />
此连接器负责和其他的http服务器建立连接,再把tomcat与其他的http服务集成时需要使用此连接器。如果此端口被占用,可在配置文件中将8009改成其他端口
(4)<connector port="8443" protocol="http/1.1" sslenabled="true"
maxthreads="150" scheme="https" secure="true" clientauth="false"
keystorefile="d:\tomcat6.0\conf\tomcat.key" keystorepass="123456"
sslprotocol="tls" />
此连接器的作用是启动https服务,一般的情况此段内容是被注释掉的,只有开启https服务时才会放开使用,如果此端口被占用则修改8443端口为其他没被占用的端口,并且需要将(1)和(3)中的也要修改
3. 修改成功后,为了使新设置的端口生效,还需要重新启动tomcat服务器。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/elementf/article/details/73401077