Set Cache Controls in Elastic Beanstalk

Updated Jan 25, 2018

This post is part of the series WordPress and Elastic Beanstalk.

Enabling caching on your server improves overall site performance as browsers can rely on previously downloaded files for returning visitors. 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”. They are processed in alphabetical order. In this case we’ll name the file cache.config:

cache.config Download Copy
mode: "000444"
owner: root
group: root
content: |
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 day"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month”
ExpiresByType text/javascript "access plus 1 month”
ExpiresByType application/javascript "access plus 1 month”
ExpiresByType image/ico "access plus 1 month"
ExpiresByType text/html "access plus 600 seconds"

Put the above file in your .ebextensions directory in your source bundle and you should be all set. Feel free to ask questions or suggest improvements in the comments section below.

Comments Leave a comment

  • CJ
    Very helpful and worked on my wordpress site perfectly. Thank you.
    • EssyCodeModerator
      Thanks for the comment, glad it helped!
  • fk
    Thanks a lot. Keep the good work going
  • skc
    Thanks ! This made deployment easy for me.
    • EssyCodeModerator
      Great, glad it was helpful! Thanks for the note.

Leave a comment