SoFunction
Updated on 2025-03-08

Tomcat configuration method using both http and https access

For some projects in tomcat that require SSL encryption and some can be directly accessed, it can be achieved by modifying the one under tomcat/conf. For specific configuration, please refer to the following code, and pay attention to the configuration in the <Service name=”Catalina1”> tag.

&lt;?xml version='1.0' encoding='utf-8'?&gt;
&lt;Server port="8005" shutdown="SHUTDOWN"&gt;
  &lt;Listener className="" SSLEngine="on" /&gt;
  &lt;Listener className="" /&gt;
  &lt;Listener className="" /&gt;
  &lt;Listener className="" /&gt;
  &lt;Listener className="" /&gt;
  &lt;GlobalNamingResources&gt;
    &lt;Resource name="UserDatabase" auth="Container"
      type=""
      description="User database that can be updated and saved"
      factory=""
      pathname="conf/" /&gt;
  &lt;/GlobalNamingResources&gt;
 
  &lt;Service name="Catalina"&gt;
    &lt;!-- Used heresslConfiguration,NeededhttpsOnly accessible --&gt;
    &lt;Connector port="8284" protocol="HTTP/1.1"
      connectionTimeout="20000"
      redirectPort="8443" URIEncoding="UTF-8"
      clientAuth="false" sslProtocol="TLS"
      SSLEnabled="true" scheme="https" secure="true"
      keystoreFile="conf/" keystorePass="pico2012server"
      truststoreFile="conf/" truststorePass="pico2012server"
      /&gt;
    &lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /&gt;
 
    &lt;Engine name="Catalina" defaultHost="localhost"&gt;
 
      &lt;Realm className=""&gt;
        &lt;Realm className=""
          resourceName="UserDatabase"/&gt;
      &lt;/Realm&gt;
 
      &lt;Host name="localhost" appBase="webapps"
        unpackWARs="true" autoDeploy="true"&gt;
        &lt;Valve className="" directory="logs"
          prefix="localhost_access_log." suffix=".txt"
          pattern="%h %l %u %t &amp;quot;%r&amp;quot; %s %b" /&gt;
 
      &lt;/Host&gt;
    &lt;/Engine&gt;
  &lt;/Service&gt;
 
  &lt;!-- 加入一个新的网站服务Configuration,Eachservice都可以单独Configurationproject加载目录、Ports, etc. --&gt;
  &lt;Service name="Catalina1"&gt;
    &lt;!-- Here it means that the loaded project still uses the originalhttpAccess --&gt;
    &lt;Connector port="8484" protocol="HTTP/1.1"
      connectionTimeout="20000"
      redirectPort="8443" URIEncoding="UTF-8"
      /&gt;
    &lt;Connector port="18009" protocol="AJP/1.3" redirectPort="18443" /&gt;
 
    &lt;Engine name="Catalina1" defaultHost="localhost"&gt;
      &lt;Realm className=""&gt;
        &lt;Realm className=""
          resourceName="UserDatabase"/&gt;
      &lt;/Realm&gt;
      &lt;!-- ShouldserviceLoaded project placement directory,andwebappsThe same directorywebapps1 --&gt;
      &lt;Host name="localhost" appBase="webapps1"
        unpackWARs="true" autoDeploy="true"&gt;
 
        &lt;Valve className="" directory="logs"
          prefix="localhost_access_log." suffix=".txt"
          pattern="%h %l %u %t &amp;quot;%r&amp;quot; %s %b" /&gt;
        &lt;!-- The specified load to be displayed herewebapps1NextGS-Webproject --&gt;
        &lt;Context path="" docBase="GS-Web" debug="0" reloadable="true"/&gt;
      &lt;/Host&gt;
    &lt;/Engine&gt;
  &lt;/Service&gt;
&lt;/Server&gt;

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.