【问题标题】:Why Gzip compression not work in aws-elasticbeanstalk + nginx + tomcat environment?为什么 Gzip 压缩在 aws-elasticbeanstalk + nginx + tomcat 环境中不起作用?
【发布时间】:2022-01-31 18:05:18
【问题描述】:

系统已在 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

目前仅获取这些响应标头

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

也尝试为邮递员添加此标头

'accept-encoding: gzip'

【问题讨论】:

  • 在您的请求中,您是否发送Accept-Encoding 标头?也许那是缺失的,这就是服务器没有使用 gzip 压缩响应的原因。
  • 是的,已添加到应用程序属性文件中。问题已更新

标签: amazon-web-services nginx tomcat amazon-elastic-beanstalk gzip


【解决方案1】:

应用后的效果

@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>
            

发挥魅力 :-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-23
    • 2017-12-27
    • 1970-01-01
    相关资源
    最近更新 更多