Search code examples
amazon-web-servicesnginxtomcatamazon-elastic-beanstalkgzip

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


The system is up and running in elasticbeanstalk here is added configs in the .ebextensions folder (located in folder root)

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;

Tried with tomcat-settings.config too, but the result is the same

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

only getting these response headers yet

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

Application properties file

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

Tried by adding this header for postman too

'accept-encoding: gzip'

Solution

  • its works after apply this

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

    dependency used this one

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

    work as a charm :-)