How to achieve gzip compression in Nodejs deployed using Elastic Beanstalk on Amazon Linux 2 platform?

Viewed 823

As per the docs they have removed the GzipCompression option using the config on Amazon Linux 2 platform versions.

1 Answers

As all AL2 based platform use nginx as default reverse proxy, you can turn on GzipCompression in nginx configuration by overriding default nginx.conf, or by adding additional configuration files.

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html#platforms-linux-extend.proxy.nginx

To extend the Elastic Beanstalk default nginx configuration, add .conf configuration files to a folder named .platform/nginx/conf.d/ in your application source bundle. The Elastic Beanstalk nginx configuration includes .conf files in this folder automatically.

~/workspace/my-app/
|-- .platform
|   `-- nginx
|       `-- conf.d
|           `-- myconf.conf
`-- other source files

To override the Elastic Beanstalk default nginx configuration completely, include a configuration in your source bundle at .platform/nginx/nginx.conf:

~/workspace/my-app/
|-- .platform
|   `-- nginx
|       `-- nginx.conf
`-- other source files

In nginx default configuration of EB platforms based on AL2, there are already gzip compression options in nginx.conf file which is 'gzip off;'. If you choose to extend default nginx configuration, you also need to delete this configurations in nginx.conf file.

The gzip configuration that should be included in nginx config file will be like this.

gzip on;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
Related