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.

  • 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 '14 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. – Scott Joudry Jul 17 '14 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 '14 at 14:27
  • setting updated, waiting....I'll let you know if that takes care of it. – Scott Joudry Jul 17 '14 at 14:30
  • Good call MPD - everything is working now! I'll write that up as an answer – Scott Joudry Jul 17 '14 at 14:43
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

  • 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. – millionleaves Oct 3 '17 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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