欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

tomcat同时使用http和https访问的配置方法

程序员文章站 2022-03-19 08:27:08
针对一个tomcat中有的项目需要使用ssl加密有些可以直接访问的情况,可通过修改tomcat/conf下的server.xml来实现。具体配置可参考下面这段代码,注意&l...

针对一个tomcat中有的项目需要使用ssl加密有些可以直接访问的情况,可通过修改tomcat/conf下的server.xml来实现。具体配置可参考下面这段代码,注意<service name=”catalina1″>这个标签中的配置。

<?xml version='1.0' encoding='utf-8'?>
<server port="8005" shutdown="shutdown">
  <listener classname="org.apache.catalina.core.aprlifecyclelistener" sslengine="on" />
  <listener classname="org.apache.catalina.core.jasperlistener" />
  <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">
    <!-- 此处使用了ssl配置,需用https才可访问 -->
    <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/tomcat.jks" keystorepass="pico2012server"
      truststorefile="conf/tomcat.jks" truststorepass="pico2012server"
      />
    <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都可以单独配置工程加载目录、端口等 -->
  <service name="catalina1">
    <!-- 此处表示加载的工程仍使用原始的http方式访问 -->
    <connector port="8484" protocol="http/1.1"
      connectiontimeout="20000"
      redirectport="8443" uriencoding="utf-8"
      />
    <connector port="18009" protocol="ajp/1.3" redirectport="18443" />
 
    <engine name="catalina1" defaulthost="localhost">
      <realm classname="org.apache.catalina.realm.lockoutrealm">
        <realm classname="org.apache.catalina.realm.userdatabaserealm"
          resourcename="userdatabase"/>
      </realm>
      <!-- 该service加载的工程放置目录,与webapps同目录的webapps1 -->
      <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" />
        <!-- 此处要显示的指定加载webapps1下的gs-web工程 -->
        <context path="" docbase="gs-web" debug="0" reloadable="true"/>
      </host>
    </engine>
  </service>
</server>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。