tomcat同一端口绑定多域名开启SSL

需求是tomcat一个443端口,配置两个域名ssl证书。查了一些资料总结如下:

1.需要tomcat 8.5 版本以上,低版本不支持配置多个。我用的版本是8.5.58 ,如果你用更高版本的tomcat也是可以的。我之所以用8.5.58版本的是因为

我的jdk是1.7 的。

conf下的server.xml文件。配置如下

<?xml version="1.0" encoding="UTF-8"?>
  <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">
    <!-- 80端口专向443端口 -->
    <Connector port="80" protocol="HTTP/1.1"
              connectionTimeout="20000"
              maxHttpHeaderSize="8192"
              maxThreads="1000"
              minSpareThreads="25"
              maxSpareThreads="75"
              enableLookups="false"
              compression="on"
              compressionMinSize="2048"
              compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
              redirectPort="443" />
    <!-- 
      443端口配置了两个域名对应两个证书,注意defaultSSLHostConfigName参数的值必须与SSLHostConfig中的一个的hostName相同,
      即defaultSSLHostConfigName="www.aaa.com" 或 defaultSSLHostConfigName="www.bbb.net" ,官方文档就是这么要求的。
     -->
    <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
      maxThreads="150" SSLEnabled="true" defaultSSLHostConfigName="www.aaa.com">
      <SSLHostConfig hostName="www.aaa.com">
          <Certificate certificateKeystoreFile="cert/3098620_www.aaa.com.pfx"
              certificateKeystorePassword="xxx" 
              certificateKeystoreType="PKCS12" />
      </SSLHostConfig>
      <SSLHostConfig hostName="www.bbb.net">
          <Certificate certificateKeystoreFile="cert/4536437_www.bbb.net.pfx"
              certificateKeystorePassword="xxx" 
              certificateKeystoreType="PKCS12" />
      </SSLHostConfig>
    </Connector>
    <!-- 777端口配置了一个域名,就不需要上面那么复杂了。 -->
    <Connector port="777" protocol="org.apache.coyote.http11.Http11NioProtocol"
            maxThreads="150" SSLEnabled="true" >
      <SSLHostConfig>
           <Certificate certificateKeystoreFile="cert/4333994.net.pfx"
              certificateKeystorePassword="xxx" 
              certificateKeystoreType="PKCS12" />
      </SSLHostConfig>
    </Connector>
    <Connector protocol="AJP/1.3" 
               address="::1" port="8009" 
               redirectPort="443" 
               secretRequired="" />
    <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 path="/" docBase="/home/website/" reloadable="false" />
      </Host>
    </Engine>
  </Service>
</Server>

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值