tomcat changes the http protocol to https protocol, and Websocket requests the ws protocol to be changed to wss protocol

tomcat changes the http protocol to https protocol, and Websocket requests the ws protocol to be changed to wss protocol

1. Description

  1. Both the WS protocol and the WSS protocol are SCHEM of the WebSocket protocol. One of them is non-secure, the other is secure, and they are also unified resource identifiers. Just like the difference between HTTP protocol and HTTPS protocol. The non-secure one does not have a certificate, and the secure one requires an SSL certificate. (SSL was developed by Netscape to ensure the security of data transmission in the network. It mainly uses data encryption technology to prevent data from being stolen or monitored during the transmission process.) WSS represents WebSocket on top of TLS. WS generally defaults to port 80, while WSS defaults to port 443.
  2. The wss protocol should be used for secure links under https, and wss does not support the writing of ip addresses, so they should be written in the form of domain names.
 http -> new WebSocket('ws://xxx')
 https -> new WebSocket('wss://xxx')

2. Operation:
The project does not need to make any modifications
3. Apply for a certificate
4. Place the certificate in tomcat's conf folder
5. Modify tomcat's server file
Find the commented out section of code in the server.xml file
Insert image description here
Uncomment and make the following changes

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA"  certificateKeystorePassword="1111"/>
        </SSLHostConfig>
    </Connector>

certificateKeystoreFile:certificate pathcertificateKeystorePassword
:certificate password

Now you can use https protocol and wss protocol, but when accessing, use the domain name set when applying for the certificate.

Guess you like

Origin blog.csdn.net/weixin_44021888/article/details/107714391