tomcat8.5/7.0配置https连接

让tomcat支持https协议,HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。

1、产生秘钥对

keytool -genkey -alias tomcat -keyalg RSA

秘钥文件:

2、配置tomcat服务器的https连接器:

将秘钥文件拷贝到tomcat的conf文件中

3、配置https连接器:

在server.xml中添加如下配置:

(1)tomcat8版本

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/.keystore"
                        certificateKeystorePassword="123456"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

(2)tomcat7版本

<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" 
        maxThreads="150" SSLEnabled="true" 
        scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" 
        keystoreFile="conf/.keystore" keystorePass="123456" 
        truststoreFile="conf/.keystore" 
        truststorePass="123456"/>

4、重启tomcat服务器,浏览器输入:https://localhost:8443/hello/

       hello为tomcat->webapps文件夹下的项目根路径

      

浏览器输入https://localhost:8443/hello/响应如下:

 

猜你喜欢

转载自blog.csdn.net/qq_34361514/article/details/82663626