Cloudfront issue

0

I have pushed the new images to my server. When I make a request to CloudFront, it fails to fetch the image from the origin because it is not cached before, and it throws multiple 301 redirects. However, after clearing the cache in CloudFront, I can see the new image. But again, CloudFront sends a request to the origin and gets the response. When I make a request for the first time, it fails, but after clearing the cache, it works. What could be the reason?

Thanks in advance!

已提問 2 個月前檢視次數 189 次
1 個回答
0

The issue you are facing is likely due to the way CloudFront handles the initial request for an object that is not yet cached in the Edge Locations.

Here's what typically happens when you request an object from CloudFront for the first time:

1 - CloudFront receives the request and checks if the object is cached in the Edge Location closest to the client.
2 - If the object is not cached, CloudFront sends a request to the origin server (your server) to fetch the object.
3 - During this initial request to the origin server, CloudFront follows any redirects (301 or 302) that the origin server may respond with.
4 - Once CloudFront receives the final response from the origin server (after following any redirects), it caches the object in the Edge Location.
5 - CloudFront then serves the cached object to the client.\

The issue you are facing is likely caused by the 301 redirects that your origin server is sending during the initial request from CloudFront. Since CloudFront follows these redirects, it may be causing a failure or timeout before it can retrieve and cache the object.

If your origin returns a redirect status code (for example, 301 or 307), CloudFront doesn’t follow the redirect. CloudFront passes along the 301 or 307 response to the viewer, who can follow the redirect by sending a new request.

I recommend you to check How CloudFront processes HTTP 3xx status codes from your origin.

profile pictureAWS
已回答 2 個月前
profile picture
專家
已審閱 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南