4

I have an elastic beanstalk server running an Apache proxy on Amazon Linux 2. I want to set the cache-control header on my index.html file to public, max-age=0.

In order to update my Apache config I understand I can add a config file to .platform/httpd/conf.d. In my first attempt I created this file:

<FilesMatch "index\.html">
   Header set Cache-Control "public, max-age=0"
</FilesMatch>

This did not work. Looking around I think this is because the directives I have used are intended for Apache's htaccess file or within a <VirtualHost> section of the conf file.

Any ideas how I can get this working? Note I found this answer had some useful information.

EDIT: I also tried this in a conf file (it didn't set any cache-control headers).

<IfModule mod_expires.c>
# Turn on the module.
ExpiresActive on
# Set the default expiry times.
ExpiresDefault "access plus 2 days"
ExpiresByType text/html "access plus 600 seconds"
</IfModule>

EDIT: I also tried switching to nginx. I added a file .platform/nginx/conf.d/cache.conf, with the following contents

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 2d;
    add_header Cache-Control "public, no-transform";
}

After deployment and a server restart, no cache-control headers were set on the files specified.

F_SO_K
  • 13,640
  • 5
  • 54
  • 83
  • Did you ever sort this? I've just noticed I have same issue. – HenryM Jan 06 '22 at 12:00
  • I couldn't get it working using ELB configurations, no. In the end I used a CloudFront Lambda Edge script. Basically, a very simple 'origin response' script that adds the required header. – F_SO_K Jan 06 '22 at 14:16

0 Answers0