Configuration method for enabling gzip compression in Tomcat7

  • 2020-05-12 06:31:04
  • OfStack

Use gzip compression to reduce data transfer size and speed up page loading. Many large websites have turned on gzip compression, but many websites have not turned on gzip compression. I read an article last time that turning on gzip compression is not friendly to search engines, but from the perspective of bandwidth and traffic, it is necessary to turn on gzip compression.
For the tomcat7 server, open the server.xml file in the conf folder and find


<Connector port="8080" protocol="HTTP/1.1"
                    connectionTimeout="20000"
                    redirectPort="8443" />

Is amended as:

<Connector port="8080" protocol="HTTP/1.1"
                    connectionTimeout="20000"
                    redirectPort="8443"
                    compression="on"
                    compressionMinSize="2048"
                    noCompressionUserAgents="gozilla,traviata"
                    compressableMimeType="text/html,text/xml,text/javascript,application/x-javascript,application/javascript,text/css,text/plain"/>

Save exit, restart the tomcat server. ps: you can use the following website to test whether gzip is enabled:

http://www.gidnetwork.com/tools/gzip-test.php


Related articles: