Cloud server Tomcat configuration Https request

1. Tomcat version: tomcat9 (other versions should be similar, try it yourself)
        Note: By this step, you are already proficient in using cloud servers by default, such as port opening, firewall update, etc. If you have any questions, just leave a message in the comment area.
2. SSL certificate application
        In the cloud server you purchased, apply for an ssl certificate. The cloud is hidden a little bit deeper. Everyone chooses a single domain name, and then chooses a free DV SSL certificate, and then the choice of brand may change, but anyway. The free one is right. On the contrary, Tencent Cloud is more friendly (this is currently the case in 2020, not necessarily in the future), and you can choose a free certificate with one click.
Insert picture description here
Three, Tomcat configuration

  1. Place the certificate file in the tomcat/conf directory of the cloud server.
  2. Open the conf/server.xml file for editing (Tomcat9 generally defaults port 8083):
    change: <Connector connectionTimeout="20000" port="8083" protocol="HTTP/1.1" redirectPort="8490" />
    to: <Connector connectionTimeout="20000" port="8083" protocol="HTTP/1.1" redirectPort="443" />
    then add:
<Connector port="443" SSLEnabled="true" clientAuth="false" keystoreFile="conf/example.com.cn.pfx" keystorePass="你的证书密码" maxThreads="150" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="443" />

Note: keystoreFile is the storage location of the certificate file, we just put it in the conf directory. keystorePass is the certificate password.

  1. Open the conf/web.xml file for editing (not necessary, here is to force all requests to be https, including ip, configuration is not recommended for multiple services)
 <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>

        If nothing else, you can access the deployed web project through the domain name.

Guess you like

Origin blog.csdn.net/weixin_43899542/article/details/106594066
Recommended