Myluzh Blog

Strive to become a dream architect.

Tomcat配置https SSL证书

发布时间: 2020-8-13 文章作者: myluzh 分类名称: OPS


0x01 上传证书
证书申请完后,选择Tomcat版本证书文件下载,下载后打开会有两个文件一个是.jks证书还有个是证书秘钥,找到.jks文件上传到tomcat目录conf目录下。

0x02 配置server.xml
找到Tomcat目录中conf目录下server.xml
配置以下代码:(443为https默认访问端口)
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
             maxThreads="150" scheme="https" secure="true"
             keystoreFile="conf/domains.jks"    //证书文件路径
             keystorePass="ah52ayp8zr"         //证书密钥
             clientAuth="false" sslProtocol="TLS" />

为了让http访问自动跳转为https访问,要进行如下修改:
找到:
点击查看原图
改成:
点击查看原图
找到:
点击查看原图
改成:
点击查看原图
注意:若最后启动tomcat时候报:Catalina.start using conf/server.xml: Element type "Connector" must be followed by either attribute ,请注意不要分行,每个属性间隔一个空格保存就好。

0x03 配置web.xml
编辑web.xml,在该文件</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>

0x04 最后
保存,退出,重启tomcat服务即可

标签: tomcat https ssl

发表评论