( 1 ) 使用java jdk将PFX格式证书转换为JKS格式证书(windows环境注意在%JAVA_HOME%/jdk/bin目录下执行)
keytool -importkeystore -srckeystore 1533096439647.pfx -destkeystore your-name.jks -srcstoretype PKCS12 -deststoretype JKS
回车后输入JKS证书密码和PFX证书密码,强烈推荐将JKS密码与PFX证书密码相同,否则可能会导致Tomcat启动失败。
( 2 ) 找到安装 Tomcat 目录下该文件Server.xml,一般默认路径都是在 conf 文件夹中。找到 <Connection port="8443"标签,增加如下属性:
keystoreFile="cert/your-name.jks"
keystorePass="证书密码"
完整的配置如下,其中port属性根据实际情况修改:
修改server.xml,cert文件夹在tomcat安装目录下
<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
keystoreFile="cert/your-name.jks"
keystorePass="1533096439647"
clientAuth="false" sslProtocol="TLS" />
修改web.xml
在最后面位置 </welcome-file-list>下面添加如下代码实现http自动跳转https:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<security-constraint>
<!-- Authorization setting for SSL -->
<web-resource-collection >
<web-resource-name >SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>