tomcat支持兩個ssl鏈接的方法:
打開server.xml配置,代碼如下:
<?xml version="1.0" encoding="UTF-8"?><!-- 訪問 80 重定向到 443 -->
<Connector port="80" maxHttpHeaderSize="8192" address="0.0.0.0"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<!-- 特別注意 defaultSSLHostConfigName 要配置一個默認的訪問域名 -->
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" defaultSSLHostConfigName="www.test.a.com">
<SSLHostConfig hostName="www.test.a.com">
<Certificate certificateKeystoreFile="D:\tomcat\apache-tomcat-8.5.20\cert\1\a.pfx" certificateKeystorePassword="a的密碼"
certificateKeystoreType="PKCS12" />
</SSLHostConfig>
<SSLHostConfig hostName="www.test.b.com">
<Certificate certificateKeystoreFile="D:\tomcat\apache-tomcat-8.5.20\cert\2\b.pfx" certificateKeystorePassword="b的密碼"
certificateKeystoreType="PKCS12" />
</SSLHostConfig>
</Connector>
<Connector port="8009" protocol="AJP/1.3" redirectPort="443" />
<Engine name="Catalina" defaultHost="www.test.a.com">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<!-- 這里配置的兩個域名訪問的是同一個 項目 -->
<Host name="www.test.a.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Alias>www.test.a.com</Alias>
<Alias>www.test.b.com</Alias>
<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>