使用的是UCloud的免费证书:

教程:

https://docs.ucloud.cn/security/ussl/index

购买证书的地址:

https://console.ucloud.cn/ussl/ussl

 

根据教程,会有jks文件,及自己定义的密钥,后边是配置tomcat。

首先把jks放入tomcat的conf目录。

然后配置server.xml

<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>前添加;

<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" />

  

 

相关文章:

  • 2021-08-17
  • 2021-10-22
  • 2021-08-27
  • 2021-06-12
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-09
  • 2022-03-09
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2021-07-28
相关资源
相似解决方案