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:
Line 1 Declare that we’re adding files in this config.
Line 2 Specify the file location. This will be processed by httpd on startup.
Lines 3-5 Set permissions and ownership for the file to give read access to everyone.
Lines 7-19 This is the content of the file. Change the expiration dates according to your needs.
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