I am trying to understand CDN and caching and am not finding the answer.
How do you make amazon cdn cache the images from your origin servers cached images? And is there a way to test for it?
I have the CDN origin mapped to my server, so when it is not finding
http://cdn.mywebsite.com/media/catalog/product/cache/1/small_image/190x/9df78eab33525d08d6e5fb8d27136e95/i/m/img101.jpg
it instead looks for
http://mywebsite.com/media/catalog/product/cache/1/small_image/190x/9df78eab33525d08d6e5fb8d27136e95/i/m/img101.jpg
You can see in Firebug, all the magento-cached elements are getting a 301 moved permanently, while the static files get an OK 200 response. Also if I enter the cloudfront URL it automatically changes to my url for magento-cached elements, but remains as the cloudfront url for the static ones.
If I go back later, even a full day, it never uses the CDN source, leading me to believe that its not caching my magento-cached css/js/images on Amazon.
If I turn off caching & js/css optimization, then it makes an excessive amount of http request to the cloudfront cdn.
When Cloudfront asks your server (the origin) for the file for some reason your server is not answering with a 200. You should check your logs and rewrite rules to determine why Cloudfront is receiving the 301 response.
One explanation I can think of is if you've got a rule which redirects to www.*, etc.
I had a similar problem and the cause was not unlike Gordon Knoppe's answer. I had a page with a large number of thumbnail images that should have been served by my CloudFront CDN. Odd thing was 2 out of 3 were not and those that were not were showing "301 - Permanent Redirected" with Fiddler.
Turns out the URL path of the image could contain uppercase letters (some did, some didn't) and for those that did they collided with a Rewrite rule that ensured all URLs were handled as lower case. The net result is the CloudFront request only cached on 200 replies and not on 301's returned when the path was not lower case. Once the URL path was fixed up to be all lower case, everything worked fine.
willboudle
I have Implemented exact thing with Amazon cloudfront, S3 and amazon OnePica Extension.
So OnePica already took care of the Product images for S3 and Cloudfront. But For Css & Js we have customize our code. We customize Mage_Core_Helper_Data::mergeFiles()
& Mage_Core_Model_Design_Package::getMergedJsUrl($files)
and Mage_Core_Model_Design_Package::getMergedCssUrl($files)
methods
Ofcourse you need to change you Media URL to the cloudfront URL. Just a word of advise if you want that your files should be Gzipped. then you have to gzip ur CSS & JS file and then upload to S3 server.
Hope This will help you