6

Yesterday I installed the CDN Module using Amazon Cloudfront and magically everything worked as expected. I was quite happy.

This morning I was showing off my new improved CDN enabled website to a colleague and most (not all) of the image style generated images were broken! And to confuse things even further, when I opened a broken image in a browser window the file was actually Drupal's Access Denied Page.

Digging into this further, I found that the /sites/default/files/styles/STYLE folder was empty. This seems strange to me since it was not empty yesterday when all of these files were uploaded to Amazon. What could be deleting the styles/STYLE folder?

So, I installed the Image Style Flush Module and flushed the style in question. Still nothing, but it makes sense since the CDN module is re-writting all of the links to static content and Drupal doesn't actually get hit to re-create the missing image. How the Access Denied page was uploaded is a mystery as well.

Next, I disabled the CDN module and cleared the cache. Reloading the page recreated all of the images and everything works as expected. But, I need to use the CDN as it's a requirement of the project.

Drupal 7.27, CDN module latest version.

I could blacklist the /sites/default/files/styles/STYLE folder, but that represents almost 30 images that are loaded on every page.

Any advice would be greatly appreciated.

5
  • Do you see the inbound request in your Apache logs? I had a CloudFront problem a few months ago where I was getting malformed headers, and my Apache was denying the request. I think an Apache upgrade fixed it (I think that server was on the Apache 2.2 tree).
    – mpdonadio
    Jul 17, 2014 at 14:20
  • There are access denied errors in the dblog and 403 errors in the apache log. The access denied errors in the dblog are missing the image style token...I'll look into that. Jul 17, 2014 at 14:26
  • 1
    It's a setting in CloudFront. You need to tick a checkbox related to query parameters. If you figure it out, write it up as an answer.
    – mpdonadio
    Jul 17, 2014 at 14:27
  • setting updated, waiting....I'll let you know if that takes care of it. Jul 17, 2014 at 14:30
  • Good call MPD - everything is working now! I'll write that up as an answer Jul 17, 2014 at 14:43

1 Answer 1

7

AD MPD noted in the comments, the issue is how Amazon Cloudfront handles the image style URL, specifically the ?itok query string.

So, when creating your distribution in Cloudfront, make sure you set "Forward Query Strings" to "Yes". See screenshot:

enter image description here

1
  • Confirmed that this was the solution for me. The only reason to add anything here is to note that the option to forward query strings is now labeled Query String Forwarding and Caching. The default is none. I chose Forward all, cache based on all. The alternative was Forward all, cache based on whitelist. Oct 3, 2017 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.