serverless-image-handler icon indicating copy to clipboard operation
serverless-image-handler copied to clipboard

set up custom domain then my link always returns "X-Cache: Miss from cloudfront"

Open onggiabayluon opened this issue 5 years ago • 2 comments

I'm trying to solve my problem like (issue #160) I using my domain on cloudflare because I want to use Firewall from cloudflare to prevent hotlink but i keep getting x-cache miss if I using cloudflare by poiting my custom domain from cloudflare to API gateway Distribution instead of cloudfront Distribution here is my link https://api.cloudimagewall.xyz/401x0/toi-la-nguoi-choi-duy-nhat-dang-nhap/chapter-2/1620552516056-0_1.jpg But it not worked, I still got x-cache miss even I Crtl F5 to reload several times

image image Can someone help me please 😭 I just want to make hotlink protection but issue keep coming XD I stuck so long in this

onggiabayluon avatar May 10 '21 02:05 onggiabayluon

@onggiabayluon Thanks for contacting us. I've researched this one a bit, and I think this could be helpful for you. https://community.cloudflare.com/t/cloudflare-and-cloudfront-show-cache-hit/129955

Since you're using CloudFlare in front of CloudFront, I think your CloudFlare caches the result from the CloudFront. Therefore, in the response headers, you would see cf-cache-status header is HIT but x-cache header is Miss from cloudfront.

beomseoklee avatar May 10 '21 16:05 beomseoklee

@onggiabayluon Thanks for contacting us. I've researched this one a bit, and I think this could be helpful for you. https://community.cloudflare.com/t/cloudflare-and-cloudfront-show-cache-hit/129955

Since you're using CloudFlare in front of CloudFront, I think your CloudFlare caches the result from the CloudFront. Therefore, in the response headers, you would see cf-cache-status header is HIT but x-cache header is Miss from cloudfront.

Ah, I think you're right. Because Cloudflare Cache layer on top of the cloudfront make cloudfront x-cache always show miss if I purge Cloudflare cache then I can see x-cache get Hit

my Solution to fix this problem is set a rule in cloudflare like this: image so this setting mean disable cache on Cloudflare then the result now I get x-cache hit in Cloudfront normally image

I dont know if this is ok to remove Cloudflare Cache like this, After all I can use Cloudflare Firewall to block referer header now and my cloudfront x-cache also Hit I really appreciate your help

onggiabayluon avatar May 11 '21 01:05 onggiabayluon