Tomcat启用HTTPS配置

获取证书

  可使用jdk自带的keytool开生成证书,此种方式与向第三方权威机构购买的证书的区别为,第一次请求时需要选择信任站点并继续访问,在浏览器的地址框里会显示不安全的红色提醒。

  使用keytool -genkey -alias tomcat -validity 3650 -keyalg RSA -keystore D://.keystore即可在D盘生成.keystore文件,如下所示

PS C:\Users\YiYing\Desktop> keytool -genkey -alias tomcat -keyalg RSA -keystore D://.keystore
输入密钥库口令:
再次输入新口令:
您的名字与姓氏是什么?
  [Unknown]:  YI
您的组织单位名称是什么?
  [Unknown]:  CSS
您的组织名称是什么?
  [Unknown]:  CSS
您所在的城市或区域名称是什么?
  [Unknown]:  BJ
您所在的省/市/自治区名称是什么?
  [Unknown]:  BJ
该单位的双字母国家/地区代码是什么?
  [Unknown]:  CHINA
CN=YI, OU=CSS, O=CSS, L=BJ, ST=BJ, C=CHINA是否正确?
  []:  Y

输入 <tomcat> 的密钥口令
        (如果和密钥库口令相同, 按回车):
PS C:\Users\YiYing\Desktop>

说明:
- -alias为别名
- -validity 3650有效期为10年
- -keystore为生成的文件路径

Option Defaults
Below are the defaults for various option values.
-alias "mykey"

-keyalg
    "DSA" (when using -genkeypair)
    "DES" (when using -genseckey)

-keysize
    1024 (when using -genkeypair)
    56 (when using -genseckey and -keyalg is "DES")
    168 (when using -genseckey and -keyalg is "DESede")

-validity 90

-keystore the file named .keystore in the user's home directory

-storetype the value of the "keystore.type" property in the security properties file,
           which is returned by the static getDefaultType method in java.security.KeyStore

-file stdin if reading, stdout if writing

-protected false

文档地址:
https://docs.oracle.com/javase/6/docs/technotes/tools/solaris/keytool.html

Tomcat配置

  需要修改tomcat的server.xml文件,如下所示:

<!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the BIO 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 SSLEnabled="true" clientAuth="false" keystoreFile="d://.keystore" keystorePass="111111" maxThreads="150" port="8443" protocol="org.apache.coyote.http11.Http11Protocol" scheme="https" secure="true" sslProtocol="TLS"/>

  本来这一段是注释掉的,去掉注释并增加keystoreFilekeystorePass参数即可。

  最后,启动服务器,使用https://localhost:8443/即可访问服务器。

文档地址:
1. Tomcat7:https://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html
2. Tomcat8:https://tomcat.apache.org/tomcat-8.0-doc/ssl-howto.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值