Tomcat 7.0多埠配置
修改tomcat/conf目錄裡面server.xml檔案
例如下面這樣新增一個8081埠,設定下appBase目錄,這樣就可以用一個tomcat監聽多個埠,每個埠都可以放應用了。我這樣新增下面這個配置以後,tomcat就監聽了2個埠(8080,8081)
webapps目錄和webapps1目錄的應用都會啟動,可以根據不同的埠進行訪問裡面的應用
[html] view plain copy print?- <?xmlversion="1.0"encoding="UTF-8"?>
- <Serverport="8005"shutdown="SHUTDOWN">
- <Listener
- <ListenerclassName="org.apache.catalina.core.AprLifecycleListener"SSLEngine="on"/>
- <ListenerclassName="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
- <ListenerclassName="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
- <ListenerclassName="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
- <GlobalNamingResources>
- <Resourcename="UserDatabase"auth="Container"
- type="org.apache.catalina.UserDatabase"
- description="User database that can be updated and saved"
- factory
- pathname="conf/tomcat-users.xml"/>
- </GlobalNamingResources>
- <Servicename="Catalina">
- <Connectorport="8080"protocol="HTTP/1.1"
- connectionTimeout="20000"
- redirectPort="8443"/>
- <Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"/>
- <Enginename="Catalina"defaultHost="localhost">
- <RealmclassName="org.apache.catalina.realm.LockOutRealm">
- <RealmclassName="org.apache.catalina.realm.UserDatabaseRealm"
- resourceName="UserDatabase"/>
- </Realm>
- <Hostname="localhost"appBase="webapps"
- unpackWARs="true"autoDeploy="true">
- <ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="logs"
- prefix="localhost_access_log"suffix=".txt"
- pattern="%h %l %u %t "%r" %s %b" />
- </Host>
- </Engine>
- </Service>
- <Servicename="Catalina2">
- <Connectorport="8081"protocol="HTTP/1.1"
- connectionTimeout="20000"
- redirectPort="8445"/>
- <Connectorport="8010"protocol="AJP/1.3"redirectPort="8445"/>
- <Enginename="Catalina"defaultHost="localhost">
- <RealmclassName="org.apache.catalina.realm.LockOutRealm">
- <RealmclassName="org.apache.catalina.realm.UserDatabaseRealm"
- resourceName="UserDatabase"/>
- </Realm>
- <Hostname="localhost"appBase="webapps2"
- unpackWARs="true"autoDeploy="true">
- <ValveclassName="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>
<?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伺服器。