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:
files:
"/etc/httpd/conf.d/enable_cache.conf":
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"
</IfModule>
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
Leave a comment