title: Cloud-front backed with Nginx (which proxies to S3) randomly missing already cached items?
body: <p>I wish to serve images from a <strong>S3 bucket</strong> with <strong>Cloudfront</strong> as CDN frontend, for that I tried the following:</p>
  
  <blockquote>
    <p>What I <strong>wish to acheive</strong> (<strong>Attempt 2</strong>)  -- (<strong>Misses cloudfront cache randomly</strong>)</p>
  </blockquote>
  
  <p>I have the following setup to serve images: ( <strong>Cloudfront</strong> --> <strong>Nginx</strong> --> <strong>S3</strong> )
  <img src="https://i.stack.imgur.com/02iyt.png" alt="Cloudfront -&gt; Nginx -&gt; S3"></p>
  
  <p>&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Sample <strong>S3</strong> headers >>>>>>>>>>
  <img src="https://i.stack.imgur.com/0L75f.png" alt="Attempt-2 S3 headers"></p>
  
  <p>&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Sample <strong>Nginx -> S3</strong> headers (Added <strong>Cache-Control</strong>) >>>>>>>>>>
  <img src="https://i.stack.imgur.com/WFxgu.png" alt="Attempt-2 Nginx-&gt;S3 headers"></p>
  
  <p>&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Sample <strong>Cloudfront -> Nginx -> S3</strong> headers >>>>>>>>>>
  <img src="https://i.stack.imgur.com/09IhA.png" alt="Attempt-2 Cloudfront-&gt;Nginx-&gt;S3 headers"></p>
  
  <blockquote>
    <p>What I am <strong>currently working</strong> with (<strong>Attempt 1</strong>) -- (<strong>Hits cloudfront as expected everytime</strong>)</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/WfjAh.png" alt="Cloudfront -&gt; S3"></p>
  
  <p><strong>Cloudfront Settings</strong>:</p>
  
  <ul>
  <li>Respects <code>GET</code> params to support urls like (<a href="http://cdn.example.com/abc.jpg?v=1" rel="noreferrer">http://cdn.example.com/abc.jpg?v=1</a>)</li>
  <li>Cache <code>TTL</code> set to <strong>157680000</strong> ( Fallback for <strong><em>Cache-Control</em></strong> )</li>
  </ul>
  
  <p>What am I screwing up in <strong>Attemp-2</strong> with my headers ? ( <strong>Cloudfront missing randomly</strong> )</p>
  
  <p>Url(<a href="http://cdn.example.com/abc.jpg" rel="noreferrer">http://cdn.example.com/abc.jpg</a>) &amp; Url(<a href="http://cdn.example.com/abc.jpg?v=1" rel="noreferrer">http://cdn.example.com/abc.jpg?v=1</a>) both will have same <code>ETag</code>, is that fine ?</p>
  
  <p><strong>Update</strong></p>
  
  <p><strong>#AWS</strong> followed up on <strong>forums.aws.amazon.com</strong>, still waiting for a reply:</p>
  
  <p><a href="https://forums.aws.amazon.com/thread.jspa?threadID=144286&amp;tstart=0#" rel="noreferrer">https://forums.aws.amazon.com/thread.jspa?threadID=144286&amp;tstart=0#</a></p>
  
  <p><strong>Update2</strong></p>
  
  <ul>
  <li>Recent hit/miss behavioral change from cloudfront without changing anything.</li>
  <li>Earlier the hits/misses were random with no fix pattern</li>
  <li>Now, (with no change on my end) I am getting all hits 1 day and all misses the next day.</li>
  <li>This suggests that its 24 hour cache but TTL and cache headers suggest 5 year cache expiry.</li>
  <li>This is again weird and without any explanations.</li>
  </ul>
  
  <p>Hey, <strong>AWS</strong> can you see this ???</p>