Cache control for images on Object Storage

Hi,

How do you apply a caching time to files on object storage? We are uploading using linode-cli method:

/usr/local/bin/linode-cli obj put $base/$_/$hit->{image_path} org-${_} --acl-public --cluster eu-central-1

I found a few questions - but couldn't find an answer on it. I just realised we are not offering caching on all the images there :(

TIA

Andy

2 Replies

For anyone interested - I managed to get it working with a proxy_pass in nginx:

set your bucket

set $bucket_medium "foo.eu-central-1.linodeobjects.com";

# This configuration provides direct access to the Object Storage bucket:
location /bucket-medium/  {

  expires  max;
  rewrite ^/bucket-medium/(.*) /$1 break;
  resolver 1.1.1.1;
  proxy_http_version     1.1;
  proxy_redirect off;
  proxy_set_header       Connection "";
  proxy_set_header       Authorization '';
  proxy_set_header       Host $bucket_medium;
  proxy_set_header       X-Real-IP $remote_addr;
  proxy_set_header       X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_hide_header      x-amz-id-2;
  proxy_hide_header      x-amz-request-id;
  proxy_hide_header      x-amz-meta-server-side-encryption;
  proxy_hide_header      x-amz-server-side-encryption;
  proxy_hide_header      Set-Cookie;
  proxy_ignore_headers   Set-Cookie;
  proxy_intercept_errors on;
  add_header             Cache-Control max-age=31536000;
  proxy_pass             http://$bucket_medium;
}

Then you access it at yourdomain.com/bucket-medium/foo.jpg , which would equate to foo.eu-central-1.linodeobjects.com/foo.jpg

Seems to work well :)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct