我想在我的Tomcat 9.0服务器中添加SSL可能性。正如Tomcat的指令所说,我已经使用keytool生成了一个密钥,并在server.xml文件中添加了以下连接器
<Connector
protocol="org.apache.coyote.http11.Http11NioProtocol"
port="8443" maxThreads="200"
scheme="https" secure="true" SSLEnabled="true"
keystoreFile="C:\Moje_programy\spring\apache-tomcat-9.0.0.M11\klucz" keystorePass="samplepassword"
clientAuth="false" sslProtocol="TLS"/>
当我尝试启动服务器时,我收到以下错误(并且ssl端口无法正常工作):
12-Nov-2016 13:06:18.187 WARNING [main] org.apache.tomcat.util.net.openssl.OpenSSLContext.init Error initializ ing SSL context java.lang.NullPointerException
at org.apache.tomcat.util.net.openssl.OpenSSLContext.init(OpenSSLContext.java:276)
at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:100)
at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:80)
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:245)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:866)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:575)
at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:65)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:944)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:105)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:549)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:105)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:873)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:105)
at org.apache.catalina.startup.Catalina.load(Catalina.java:606)
at org.apache.catalina.startup.Catalina.load(Catalina.java:629)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:311)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:494)
我不知道是不是有些错误,或者我做错了什么......
答案 0 :(得分:5)
解决方案令人惊讶,但在密钥生成期间,别名属性必须设置为&#34; tomcat&#34;
有我的例子:
c:\Program Files\Java\jdk1.8.0_112\bin>keytool -genkey -alias tomcat -keyalg RSA -keystore C:\Moje_programy\spring\apache-tomcat-9.0.0.M11\klucz
答案 1 :(得分:1)
我在你的回答中也找到了另一个答案。您可以拥有自定义证书别名和我的方法,如下所示
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="<path to keystore>\myks.jks"
certificateKeystorePassword="abc123"
certificateKeyAlias="giganet.com"
type="RSA" />
</SSLHostConfig>
</Connector>