为什么 Gzip 压缩在 aws-elasticbeanstalk + nginx + tomcat 环境下不起作用?

Why Gzip compression not work in aws-elasticbeanstalk + nginx + tomcat environment?

系统已启动,运行 在 elasticbeanstalk 中的 .ebextensions 文件夹(位于文件夹根目录)中添加了配置

nginx-proxy.config

option_settings:
  aws:elasticbeanstalk:environment:proxy:
    GzipCompression: 'true'
    ProxyServer: nginx

gzip.config

files:
        /etc/nginx/conf.d/gzip.conf:
        content: |
                gzip on;
                gzip_types application/json application/xml text/html text/xml text/plain application/javascript text/css;
                gzip_vary on;

也尝试过 tomcat-settings.config,但结果是一样的

option_settings:
  aws:elasticbeanstalk:environment:proxy:
    GzipCompression: 'true'
    ProxyServer: nginx

仅收到这些响应 header

cache-control →no-cache, no-store, max-age=0, must-revalidate
content-type →application/json
date →Mon, 31 Jan 2022 08:31:22 GMT
expires →0
pragma →no-cache
server →nginx/1.20.0
strict-transport-security →max-age=31536000 ; includeSubDomains
vary →Origin, Access-Control-Request-Method, Access-Control-Request-Headers
x-content-type-options →nosniff
x-frame-options →DENY
x-xss-protection →1; mode=block

应用程序属性文件

server.compression.enabled=true
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css

也尝试为邮递员添加此 header

'accept-encoding: gzip'

应用后有效

@Bean
public Filter compressingFilter() {
    CompressingFilter compressingFilter = new CompressingFilter();
    return compressingFilter;
}

依赖使用了这个

    <dependency>
        <groupId>net.sourceforge.pjl-comp-filter</groupId>
        <artifactId>pjl-comp-filter</artifactId>
        <version>1.6.4</version>
    </dependency>
            

工作很有魅力:-)