tomcat配置ssl证书

时间:2025-02-04 19:05:20

1.server.xml  打开已经注释掉的代码 然后添加证书地址

<Connector SSLEnabled="true" clientAuth="want" keystoreFile="D:\mywork\apache-tomcat-8080\conf\h1024.jks" keystorePass="" keystoreType="JKS" maxThreads="150" port="8443" protocol="org.apache.coyote.http11.Http11Protocol" scheme="https" secure="true" sslProtocol="TLS" truststoreFile="D:\mywork\apache-tomcat-8080\conf\cacerts" truststorePass="" truststoreType="JKS"/>

2.在项目中web.xml中添加配置

<security-constraint>
   <web-resource-collection>
   <web-resource-name>SSL Resource</web-resource-name>
   <url-pattern>/*</url-pattern>
   </web-resource-collection>
   <user-data-constraint>
   <transport-guarantee>CONFIDENTIAL</transport-guarantee>
   </user-data-constraint>
</security-constraint>

这样当我们使用http访问自己的项目时 tomcat会给你自动转变成https