Search code examples
amazon-web-servicesapachepagespeedbitnamiamazon-lightsail

Can't enable cache control on apache server


I am running a AWS Lightsail Bitnami instance with Wordpress installed. I am trying to enable Cache Control. I have tried adding these directives to the .htaccess file:

# 1 YEAR
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|woff|woff2|ttf|eot)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

# 1 WEEK
<FilesMatch "\.(txt|xml|js|css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

I have also tried uncommenting this line in httpd.conf: LoadModule expires_module modules/mod_expires.so I added a expires.conf file in the /opt/bitnami/apache2/conf folder. I added this code:

<IfModule mod_expires.c>
  ExpiresActive on

  ExpiresByType image/jpg “access plus 60 days”
  ExpiresByType image/png “access plus 60 days”
  ExpiresByType image/js “access plus 60 days”
  ExpiresByType image/jpeg “access plus 60 days”
  ExpiresByType text/css “access plus 1 days”
</IfModule>

I restarted the apache server after these changes. My files are still not being cached. The Lightsail instance comes preconfigured with pagespeed as well.


Solution

  • Bitnami Engineer here,

    The Bitnami stacks don't use the information in the .htaccess files due to security and performance reasons. To do so, we configure Apache with "AllowOverride None" and create a htaccess.conf file inside the /opt/bitnami/apps/wordpress/conf. If you want to include any custom configuration in your app, you will need to edit that file.

    You can find more information here:

    https://docs.bitnami.com/aws/apps/wordpress/administration/use-htaccess/