如何正确配置Tomcat SSLHostConfig?

How to configure Tomcat SSLHostConfig correctly?

我按照本教程在 tomcat 中启用 ssl:https://medium.com/@raupach/how-to-install-lets-encrypt-with-tomcat-3db8a469e3d2

尽管 tomcat 最后是 运行,但我无法访问 https,说 无法连接 。所以我检查了日志,我得到了:

Caused by: java.io.IOException: SSLHostConfig attribute certificateFile must be defined when using an SSL connector

,但我的证书文件定义如您所见:

<Connector port="443"
    protocol="org.apache.coyote.http11.Http11NioProtocol"
    maxThreads="100"
    compression="on"
    scheme="https"
    SSLEnabled="true"
    secure="true"
    SSLVerifyClient="none"
    SSLProtocol="TLSv1.2"
    defaultSSLHostConfigName="test.test">
    <SSLHostConfig hostName="test.test">
        <Certificate certificateFile="conf/cert.pem" certificateKeyFile="conf/privkey.pem" certificateChainFile="conf/chain.pem" />
    </SSLHostConfig>
</Connector>

这些文件存在于 conf/

tomcat 9 个文档:https://tomcat.apache.org/tomcat-9.0-doc/config/http.html 部分 SSLHostConfig 和证书

您混合使用了新属性(自 Tomcat 8.5 起)和已弃用的属性(参见 Tomcat documentation)。设置的效果,例如SSLProtocol 是创建第二个 <SSLHostConfig> 主机名 _default_。这就是错误消息所指的元素。

您应该将过时的标签(SSLVerifyClientSSLProtocol)替换为当前对应的标签(如果您想要默认值,则忽略它们):

<Connector port="443"
           protocol="org.apache.coyote.http11.Http11NioProtocol"
           maxThreads="100"
           compression="on"
           scheme="https"
           SSLEnabled="true"
           secure="true"
           defaultSSLHostConfigName="test.test">
    <SSLHostConfig hostName="test.test"
                   protocols="TLSv1.2">
        <Certificate certificateFile="conf/cert.pem"
                     certificateKeyFile="conf/privkey.pem"
                     certificateChainFile="conf/chain.pem" />
    </SSLHostConfig>
</Connector>

备注:您使用的属性特定于 APR 连接器。如果该选择是有意的,您应该将协议更改为 org.apache.coyote.http11.Http11AprProtocol