Search code examples
apache.htaccessamazon-web-servicesamazon-ec2pagespeed

Leverage browser caching on Amazon EC2


This is my first time using Amazon AWS for any hosting and I've uploaded my usual code, below, to help with browser caching and it seems that tools like GT Metrix and Google Page speed are not seeing it work.

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType text/x-javascript "access plus 1 month"
  ExpiresByType application/x-shockwave-flash "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 year"
  ExpiresDefault "access plus 2 days"
</IfModule>

Any ideas if I need to enable anything on Amazons side for this to work?

Thanks in advance.


Solution

  • After some investigation it turned out that the Apache modules needed for this were not installed on our instance.

    What you need to do is ssh into your server as a root user and run the following command

    Check which modules are installed using this command

    apache2ctl -M
    

    and looking for expires_module. It's probably not there.

    enable browser caching

    sudo a2enmod expires
    

    restart apache

    sudo service apache2 restart