解决tomcat6.0.33 配置SSL时报“No Certificate file specified or invalid file format”异常

阅读更多

 在配置tomcat的SSL双向握手中,由于6.0.33版本中默认启用了APR(APR是通过JNI访问的可移植库,可以提高Tomcat的性能和伸缩性),所以采用传统的配置方式(如下)会报异常;

 

传统的SSL配置:

 
 

 

 

 

异常如下:

2011-10-27 9:26:03 org.apache.coyote.http11.Http11AprProtocol init
严重: Error initializing endpoint
java.lang.Exception: No Certificate file specified or invalid file format
	at org.apache.tomcat.jni.SSLContext.setCertificate(Native Method)
	at org.apache.tomcat.util.net.AprEndpoint.init(AprEndpoint.java:733)
	at org.apache.coyote.http11.Http11AprProtocol.init(Http11AprProtocol.java:107)
	at org.apache.catalina.connector.Connector.initialize(Connector.java:1022)
	at org.apache.catalina.core.StandardService.initialize(StandardService.java:703)
	at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:562)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2011-10-27 9:26:03 org.apache.catalina.core.StandardService initialize
严重: Failed to initialize connector [Connector[HTTP/1.1-443]]
LifecycleException:  Protocol handler initialization failed: java.lang.Exception: No Certificate file specified or invalid file format
	at org.apache.catalina.connector.Connector.initialize(Connector.java:1024)
	at org.apache.catalina.core.StandardService.initialize(StandardService.java:703)
	at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:562)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

 解决办法是采用下面的配置:

 
 

其实就是将protocol="HTTP/1.1"替换为protocol="org.apache.coyote.http11.Http11Protocol",问题得以解决;

APR给Tomcat的性能提升起到很大作用,建议配置APR方式。

 

题外话:

如果辨别Tomcat是否采用APR:

启动Tomcat时,如果采用APR,日志中会有如下信息:

信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].

 

如果没有采用APR,启动时则显示类似的信息:

信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: ....后面省略

 

Tomcat6.0.33版本自动集成了APR,之前的版本没有集成,需要手工配置,网上搜索会有很多这方面的教程。

 

你可能感兴趣的:(tomcat,APR,SSL)