When CloudFront Keeps Requesting Content From Your Server

On the Faith Promise website we serve images using CloudFront. Our origin server uses PHP to resize our images. While trying to cache some dynamically generated CSS I noticed that CloudFront was requesting our static content on every request. You could see this in the response header. Instead of X-Cache saying, "Hit from cloudfront" it said, "Miss from cloudfront."

The issue for me was that Nginx (I suppose) was appending "private" to my Cache-Control header, so it looked like this:

Cache-Control:max-age=31536000, private

When it should be:

Cache-Control:max-age=31536000, public

or simply leave off "private."

The solution was to manually add "public" to the header. In PHP / Laravel, this was done using:



   'max-age=31536000, public'


return $response;

About Me

I'm a web developer from Knoxville, TN. I've been married for 19 years and have two kids, four and eight years old. During the day, I work at Faith Promise Church in Knoxville, TN developing websites and helping with design. After the kids are nestled all snug in their beds, I run AgentBlaze, a small business that creates websites for real estate pros.