Nginx – Cloud-front backed with Nginx (which proxies to S3) randomly missing already cached items

amazon ec2amazon s3amazon-cloudfrontamazon-web-servicesnginx

I wish to serve images from a S3 bucket with Cloudfront as CDN frontend, for that I tried the following:

What I wish to acheive (Attempt 2) — (Misses cloudfront cache randomly)

I have the following setup to serve images: ( Cloudfront –> Nginx –> S3 )
Cloudfront -> Nginx -> S3

<<<<<<<< Sample S3 headers >>>>>>>>>>
Attempt-2 S3 headers

<<<<<<<< Sample Nginx -> S3 headers (Added Cache-Control) >>>>>>>>>>
Attempt-2 Nginx->S3 headers

<<<<<<<< Sample Cloudfront -> Nginx -> S3 headers >>>>>>>>>>
Attempt-2 Cloudfront->Nginx->S3 headers

What I am currently working with (Attempt 1) — (Hits cloudfront as expected everytime)

Cloudfront -> S3

** Cloudfront Settings **:

What am I screwing up in Attemp-2 with my headers ? ( Cloudfront missing randomly )

Url(http://cdn.example.com/abc.jpg) & Url(http://cdn.example.com/abc.jpg?v=1) both will have same ETag, is that fine ?

Best Answer

Maybe this is related to the clients making requests that indicate that cache should be by-passed?

E.g., maybe Pragma: no-cache appears in the requests, and is respected by the front-facing server, resulting in a miss?