现有文件:ssl.cer和ssl.key
- 打开在线JKS合成工具,将ssl.cer和ssl.key输入2个文本框,然后合成一个ssl.jks文件。(https://www.myssl.cn/tools/merge-jks-cert.html)
- 输入证书别名和jks密码

- 将ssl.jks 放入tomcat/config文件夹里,config目录下的server.xml
- 找到SSLHostConfig,解开注释,做好如下配置(以 http端口 8081 https端口8443 为例子)
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true"> <SSLHostConfig> <Certificate certificateKeystoreFile="conf/ssl.jks" certificateKeystorePassword="123456" type="RSA" clientAuth="false" sslProtocol="TLS" /> </SSLHostConfig> </Connector> -
配置强制跳转地址:
<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" maxPostSize="-1" maxHttpHeaderSize ="102400" RIEncoding="UTF-8" /> -
server.xml配置完成,接下来配置config下的web.xml
-
在<web-app>标签中添加以下代码(加到最后就可以,即</web-app>前)
<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> <!-- 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> -
现在整个已经配置完成,重启tomcat 。按照我上面通过配置的8081和8443端口访问 都会强制跳转到8443连接中。
-
例如ca证书的认证名字叫localhost, 那么 http://localhost:8081 和https:/localhost:8443 都会强制到https连接。将8443端口改为443,就会变成https:/localhost 访问项目。
-
参考文章:https://blog.youkuaiyun.com/hgghxl/article/details/44939351
https://blog.youkuaiyun.com/wangyuanjiet/article/details/77062169
本文介绍了如何将ssl.cer和ssl.key转换为ssl.jks文件,然后将其部署到Tomcat服务器以实现HTTPS。通过在线工具合并证书和密钥,设置证书别名和JKS密码。接着,在Tomcat的server.xml和web.xml中进行相关配置,包括SSLHostConfig和强制跳转到HTTPS。最后,通过8443端口访问时会实现强制HTTPS连接。参考了两篇优快云博客文章进行详细步骤说明。
3167

被折叠的 条评论
为什么被折叠?



