Tomcat配置HTTPS访问

一、 生成 server key :
以命令行方式切换到目录%TOMCAT_HOME%,输入如下命令:
keytool -genkey -alias tomcat -keyalg RSA -keypass changeit -storepass password -keystore server.keystore -validity 3600
这里写图片描述
参数-storepass中指定生成server key的个人密码,可以自行设置
参数 -validity 指证书的有效期(天),缺省有效期很短,只有90天。
参数 -keystore指定生成证书文件的名称

执行命令会提示输入信息,“您的名字与姓氏是什么?”这是必填项,并且必须是TOMCAT部署主机的域名或者IP[如:localhost 或者 127.0.0.1]否则浏览器会弹出警告窗口,提示用户证书与所在域不匹配。其他的可以直接回车,最后信息确认输入yes就会在%TOMCAT_HOME%目录下生成参数中指定的server.keystore文件。

二、修改tomcat配置文件
修改%TOMCAT_HOME%/conf/server.xml
找到文件中的如下配置,将注释去掉,keystoreFile、keystorePass两个参数。
keystoreFile是生成的server.keystore文件文件地址
keystorePass是-keystore参数指定的密码

<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               keystoreFile="server.keystore"    
               keystorePass="password"/>

三、验证
访问https://localhost:8443

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值