建立文件夹
/home/tomcat/tomcat-9.0.34/cert

keytool -genkey -alias Piccsug -keyalg RSA -storetype PKCS12 -keysize 2048 -sigalg SHA256withRSA -dname "CN=`hostname`,OU=Picclife,O=tomcat,L=beijing,S=beijing,C=China" -keypass PiccSug#2021 -keystore tomcat.jks -storepass PiccSug#2021 -validity 3650


server.xml中修改以下两个地方:
<Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="4430" />

复制原有的被注释掉配置,改成以下配置
<Connector port="4430"  protocol="org.apache.coyote.http11.Http11NioProtocol"
                maxThreads="150"  SSLEnabled="true">
    <SSLHostConfig>
        <Certificate certificateKeystoreFile="/home/tomcat/tomcat-9.0.34/cert/tomcat.jks"
                         type="RSA" certificateKeystorePassword="PiccSug#2021" />
    </SSLHostConfig>
</Connector>


应用web.xml中加入,以tomcat自带的项目examples为例
<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://192.168.129.138:8081/examples/
跳转:https://192.168.129.138:4430/examples/

或者直接访问:https://192.168.129.138:4430/examples/


 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐