因tomcat7以上開始支持pfx格式證書,所以本次https配置是根據(jù)pfx證書的方式配置。
tomcat還支持JKS格式證書。
大致步驟:
1. 首先可以參考阿里云的tomcat https配置:

image.png
由于ciphers字段內(nèi)容太長,將其拷貝出來:ciphers="TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA256"
keystoreFile:pfx證書所在路徑
2.根據(jù)上文配置,有些出入,如下:
(1)keystoreFile的路徑用絕對路徑表示;
(2)SSLProtocol僅填寫“TLS”,否則tomcat啟動會報錯,原因不明;
(3)protocol填寫“org.apache.coyote.http11.Http11Protocol”,不然找不到協(xié)議,tomcat也會報錯。
3. 配置conf/web.xml,讓所有http請求轉(zhuǎn)為https請求(可選)
<login-config>
<!-- Authorization setting for SSL -->
<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>
4. 重啟tomcat
注意事項:
- port端口必須是開放的,可以不僅限443端口。
- 如果是apache做解析域名的工作,則apache僅需配置成正常的http訪問方式即可。
apache配置示例:
############## for Dscake #######################
<VirtualHost *>
ServerName xcx.ews88.com
DocumentRoot "D:/www/htdocs/Dscake"
JkMount /*.jsp Dscake
JkMount /*.do Dscake
JkMount /*.html Dscake
<Directory "D:/www/htdocs/Dscake">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.jsp
</IfModule>
SetEnv force-proxy-request-1.0.1
SetEnv proxy-nokeepalive 1
CustomLog "|bin/rotatelogs D:/apacheLogs/Dscake_logs/Dscake_access_log_%Y_%m_%d_%H.log 3600 480" combined
ErrorLog "|bin/rotatelogs D:/apacheLogs/Dscake_logs/Dscake_error_log_%Y_%m_%d_%H.log 3600 480"
</VirtualHost>
############## for Dscake #######################
附錄:
- JKS格式證書安裝(阿里云)

image tomcat.png
圖中的幫助鏈接:https://help.aliyun.com/knowledge_detail/42214.html?spm=5176.2020520163.cas.53.406f1768UlMSxR