一. 创建tomcat证书
这里使用JDK自带的keytool工具来生成证书:
1. 在jdk的安装目录binkeytool.exe下打开keytool.exe
2. 在命令行中输入以下命令:
keytool -genkeypair -alias “tomcat” -keyalg “RSA” -keystore “g:tomcat.keystore”
以上命令将生产一对非对称密钥和自我签名的证书g:tomcat.keystore
注意:“名字与姓氏“应该是域名,输成了姓名,和真正运行的时候域名不符,会出问题
这里我输入的密码是123456, 域名是以tomcat为例, 省市以西安陕西为例
二. 配置tomcat服务器
定位到tomcat服务器的安装目录, 找到conf下的server.xml文件
找到如下已经被注释的代码:
1 <!–
2 <Connector port=”8443″ protocol=”HTTP/1.1″ SSLEnabled=”true”
3 maxThreads=”150″ scheme=”https” secure=”true”
4 clientAuth=”false” sslProtocol=”TLS” />
5 –>
去掉注释,修改为:
1 <Connector port=”8443″ protocol=”HTTP/1.1″ SSLEnabled=”true”
2 maxThreads=”150″ scheme=”https” secure=”true”
3 clientAuth=”false” sslProtocol=”TLS”
4 keystoreFile=”g:tomcat.keystore”
5 keys
三. 启动tomcat服务器
在IE浏览器中输入: https://对应的域名(和生成的证书一致)
选择继续浏览此网站
到此为止就搞定了
以下为网络上其他人遇到的问题以及解决方案,可以参考:
遇到的问题:
我在配置的过程中问题,当我修改了server.xml的配置后,启动tomcat报错
1 org.apache.catalina.core.StandardService initInternal
2 严重: Failed to initialize connector [Connector[HTTP/1.1-443]]
3 org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-443]]
4 at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
5 at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
6 at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
7 at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:814)
8 at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
9 at org.apache.catalina.startup.Catalina.load(Catalina.java:633)
10 at org.apache.catalina.startup.Catalina.load(Catalina.java:658)
11 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
13 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
14 at java.lang.reflect.Method.invoke(Method.java:606)
15 at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
16 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
17 Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
18 at org.apache.catalina.connector.Connector.initInternal(Connector.java:983)
19 at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
20 … 12 more
21 Caused by: java.lang.Exception: Connector attribute SSLCertificateFile must be defined when using SSL with APR
22 at org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:507)
23 at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:610)
24 at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:429)
25 at org.apache.catalina.connector.Connector.initInternal(Connector.java:981)
26 … 13 more
网上找了下,可以将protocol=”HTTP/1.1″替换为protocol=”org.apache.coyote.http11.Http11Protocol”,问题可以得以解决
原文链接:https://www.cnblogs.com/YuTaiYin/p/7343835.html
原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/32658