tomcat 开启 https 使用apr
首先,将ssl证书相关文件复制到tomcal/ssl文件夹下。然后打开 tomcat/conf/server.xml,将其相关的 8443 改成 443 端口,然后将以下节点的注释去掉。修改内容。
<Connector port="443" protocol="org.apache.coyote.http11.Http11AprProtocol" maxThreads="500" SSLEnabled="true" > <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" /> <SSLHostConfig> <Certificate certificateKeyFile="ssl/private.key" certificateFile="ssl/public.crt" certificateChainFile="ssl/intermediate.crt" type="RSA" /> </SSLHostConfig> </Connector>
配置 server.xml 文件后,还需要安装 openssl,apr,apr-util,tomcat-native 等库,tomcat 没有自带这些库。如果未安装这些类库,启动 tomcat 会报这些错误:
org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:
安装方法如下:
yum -y install openssl yum -y install apr yum -y install apr-util yum -y install tomcat-native
安装完毕后,重启 tomcat 即可。