Enabling gzip compression on your server results in smaller file sizes that need to be retrieved by the browser. To achieve this in Elastic Beanstalk running Apache we can add a configuration file to the .ebextensions directory in our source bundle.
Elastic Beanstalk will process any file in the .ebextensions directory ending in “.config”. Files are processed in alphabetical order. In this case we’ll name the file deflate.config:
Line 1 Specify that we’re adding files in this configuration.
Line 2 Specify the file name. This will be processed by httpd on start.
Lines 3-5 Set permissions and ownership for the file to give read/write access to the owner (root) and read access to everyone else.
Lines 7-29 This is the content of file.
Lines 9-17 Specify the MIME types of files to compress. This is a vanilla implementation, edit as needed.
Line 19 Set the compression level, where 1 is lowest and 9 is highest.
Lines 21-23 Handle legacy browsers with compression quirks.
Lines 25-27 Ensure we don’t send cached compressed files to the wrong browsers. See here for details.
Put the above file in your .ebextensions directory in your source bundle and you should be all set. You might also be interested in the post Set Cache Controls in Elastic Beanstalk. Feel free to ask questions or suggest improvements in the comments section below.
Comments Leave a comment
Awesome, work for me with a Flask app as well.
P.s. take note of the spacing syntax, it must be precisely as you see!
Thanks! It worked perfectly with for flask application.
Regards.
Leave a comment