How to serve images assets from AWS S3 via Cloudflare CDN with Rails and Shrine Gem?
I use the Shrine gem to upload images to AWS S3 from my Rails app.
Now I’m trying to load the asset trough Cloudflare CDN, but then my images fail to load.
Here’s my attempt to implement this
- Created an AWS S3 bucket with name cdn.myrealdomain.com
- Created a CNAME record in Cloudflare set to: Name: cdn and Host: cdn.myrealdomain.com.s3.eu-north-1.amazonaws.com
Now I can access the XLM for my bucket both trough
**s3.eu-north-1.amazonaws.com/cdn.myrealdomain.com* and trough
cdn.myrealdomain.com/ *
3. Then I added this line to my shrine.rb to set the URL HOST to my cdn.myrealdomain.com
plugin :url_options, store: { host: "https://cdn.myrealdomain.com" }
4) Now. when I start my rail server, all image assets fail to load.
If I copy image address and paste it into my browser it shows error
SignatureDoesNotMatch
**Here's the URL generated by the image_tag helper in rails (that is NOT working)**
However if I delete the trailing characters after
https://cdn.myrealdomain.com/store/48a9048cb8e5f31306417e2a1a3c7bf3.png
The image load properly.
Any suggestions to resolve this would be very much appreciated!