申请并下载tomcat的证书
在tomcat下新建一个cert目录,把证书丢进去
root@iZuf6gctxhllwhytukvaheZ:/opt/modules/tomcat-8.5/cert# ls
2146938_你的域名.pfx
大约在69行,将默认端口改为80(浏览器默认端口),redirectPort改为443,可以自定义
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
大约在88行,先去掉这段的注释,做如下更改,端口也改为443,与上面一样
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true" >
<SSLHostConfig>
<Certificate certificateKeystoreFile="证书存放路径"
certificateKeystoretype="PKCS12"
certificateKeystorePassword="证书密码"
clientAuth="false"
SSLProtocol="TLSv1+TLSv1.1+TLSv1.2"
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" />
</SSLHostConfig>
</Connector>
重启tomcat,浏览器输入地址
编辑web.xml,标签(一般在文件最末尾)添加如下,不加下面这段的话不能把http请求转为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>
注意:需要使用签发的域名进行访问,如果使用ip访问的话浏览器会谈出不信任对话框的
参考:
https://help.aliyun.com/knowledge_detail/95496.html
https://blog.csdn.net/qq_35624642/article/details/83016813