使用的是UCloud的免費證書:java
教程:web
https://docs.ucloud.cn/security/ussl/indexapache
購買證書的地址:tomcat
https://console.ucloud.cn/ussl/usslapp
根據教程,會有jks文件,及本身定義的密鑰,後邊是配置tomcat。url
首先把jks放入tomcat的conf目錄。server
而後配置server.xmlxml
<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" keystoreFile="conf/jks文件" keystorePass="自定義的密鑰" clientAuth="false" sslProtocol="TLS" />
注意,若是但願訪問http直接跳轉https的話,須要在web.xml的</web-app>前添加;blog
<login-config> <auth-method>CLIENT-CERT</auth-method> <realm-name>Client Cert Users-only Area</realm-name> </login-config> <security-constraint> <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>
若是但願既兼容http又兼容https,那麼刪除web.xml上邊配置的,同時在server.xml添加80端口配置教程
<Connector port="80" connectionTimeout="30000" redirectPort="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" />