Enable mod_deflate on AWS Elastic Beanstalk

 
 

Enabling mod_deflate module for Apache on AWS Elastic Beanstalk can be quite challenging as the environments fine tuning currently is not possible via web console yet. Luckily AWS provides some other clever ways that allows us to perform advanced configuration for Elastic Beanstalk deployments via .ebextensions (Elastic Beanstalk Extensions). By using these extensions we can perform almost any kind tweaks in terms of software for each individual environments that we have within our EB Application. In this short tutorial we will guide you, step by step as usual how to enable and configure mod_defalte module for Apache using .ebextensions for your AWS Elastic Beanstalk Environment.

Table of contents

Preparing the environment file
Writing mod_deflate.config file content
Packing and deployment
Troubleshooting

Preparing the environment file

On our very first step we have to make sure that the necessary folder and file for our solution are in place:


$ cd /to/your/application/folder
$ mkdir .ebextensions
$ cd .ebextensions
$ touch mod_deflate.config

Writing mod_deflate.config file content

On this step we have to edit our mod_deflate.config file like shown in the example below. Please pay attention to indentation as .config files present within .ebextensions are treated as .yml (YAML) files. We can have as many files needed for different modules, tweaks or packages but on this tutorial we will resume to only present enable_mod_deflate.conf to Apache. So let’s open and edit mod_deflate.config file and add the following lines:


files:
  "/etc/httpd/conf.d/enable_mod_deflate.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
       <IfModule mod_deflate.c>

        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/xml+rss
        AddOutputFilterByType DEFLATE application/x-javascript
        AddOutputFilterByType DEFLATE text/javascript
        AddOutputFilterByType DEFLATE text/css

        DeflateCompressionLevel 9

        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

         <IfModule mod_headers.c>
          Header append Vary User-Agent env=!dont-vary
         </IfModule>

       </IfModule>

Once the lines were added please just close the file and let’s move to our next and final step.

Packing and deployment

On this final step we have to compress the application files and folders and also to perform a deployment that now contains a .ebextensions folder and also a configuration file for our mod_deflate Apache module:


$ cd ..
$ zip -r my-application.zip * .[^.]*

Once the zip file is created please upload it to your Application and deploy it to your preferred environment in order to take effect.

Troubleshooting

Sometimes by simply deploying the new application version containing .ebextensions won’t enable or perform the changes specified within .config files and then we have two solution, first being to restart AWS Elastic Beanstalk Environment and if this fails then the second solution will be to rebuild the environment. If any of these fails please double check the indentation from .config file as these type of files are treated as .yml (YAML) files.

Video

No video posted for this page.

Screenshots

No screenshots posted for this page.

Source code

No code posted for this page.

About this page

Article
Enable mod_deflate on AWS Elastic Beanstalk
Author
Category
Published
11/04/2019
Updated
23/04/2019
Tags

Share this page

If you found this page useful please share it with your friends or colleagues.