TOMCAT enables multiple ports for multiple web applications

The startup configuration file of tomcat is in tomcat/conf/server.xml, and a service is configured by default:

<?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 &quot;%r&quot; %s %b" />
        <Context docBase="" path="" />
      </Host>
    </Engine>
  </Service>
</Server>

Of course, the Context element in the host is added by my configuration web project, the value of the docBase attribute points to the web application that needs to be started, and the value of the path attribute specifies the path namespace to be accessed, and I am used to setting it to an empty string

<Context docBase="" path="" />

Now you need two applications, you need to configure another Service, you need to ensure that the name attributes of the Service are different, and at the same time ensure that the HTTP port of the two sub-elements Connector and the listening port of AJP do not conflict with the port of the previous application

Another Service added is configured as follows,



  <Service name="ZeroHome">
    <Connector port="8088" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8444" />
    <Connector port="8010" 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 &quot;%r&quot; %s %b" />
        <Context docBase="" path="" />
      </Host>
    </Engine>
  </Service>

However, both web applications do start up, but there is an error message in the observation log file.

SEVERE: Creation of the naming context failed: [javax.naming.OperationNotSupportedException: Context is read only]

After trying a few times, I found that after
changing the name attribute of the Engine element to be different from the first one, the error message disappeared, and the two webs were started successfully.

<Engine name="Catalina2" defaultHost="localhost">

The specific reason for the error is still being found

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325138306&siteId=291194637