使用https进行gzip压缩可能是Tomcat

时间:2017-08-25 20:16:26

标签: https tomcat7

是否可以为https配置Tomcat(7.075) AND 同时启用gzip压缩?我无法找出server.xml中http连接器属性的有效组合来完成工作。与http:

相关的四个与压缩相关的属性
compression="on"
compressableMimeType="application/json"
compressionMinSize="8192"
useSendfile="false"

配置https时似乎没有任何效果。我当前的配置:

<Connector port="8443"
 protocol="HTTP/1.1"
 SSLEnabled="true"
 maxThreads="50"
 server="web"
 allowTrace="false"
 keystoreFile="/app/certs/keystore.jks"
 keystorePass="********"
 scheme="https"
 secure="true"
 clientAuth="false"
 sslProtocol="TLS"
 sslEnabledProtocols="TLSv1.1,TLSv1.2" 
 ciphers="TLS_..._SHA"
 maxKeepAliveRequests="100"
 connectionTimeout="20000"
 compression="on"
 compressableMimeType="application/json"
 compressionMinSize="8192"
 useSendfile="false"
 maxSwallowSize="-1"
 socket.soKeepAlive="true"/>

1 个答案:

答案 0 :(得分:2)

我使用 server.xml 的配置:

<强> 1。 http连接器

<Connector port="80" protocol="HTTP/1.1"
    connectionTimeout="20000"
    compression="on" compressionMinSize="0" useSendfile="false"
    redirectPort="443" />

<强> 2。 https连接器

<Connector port="443" protocol="org.apache.coyote.http11.Http11AprProtocol"
           maxThreads="200" SSLEnabled="true" connectionTimeout="20000"
           compression="on" compressionMinSize="0" useSendfile="false" >
    <SSLHostConfig>
        <Certificate certificateKeyFile="conf/key.crt"
                     certificateFile="conf/certificate.crt"
                     certificateChainFile="conf/chain.crt"
                     type="RSA" />
    </SSLHostConfig>
</Connector>

您可能希望将端口80更改为8080,将443端口更改为8443

UPD :如果您使用http2协议,请添加此行:

<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol"
                 compression="on" compressionMinSize="0" useSendfile="false" />