简体   繁体   English

Origin Cache-Control在AWS Cloudfront上不起作用

[英]Origin Cache-Control not working on AWS Cloudfront

I am serving my images using AWS Cloudfront. 我正在使用AWS Cloudfront提供图像。 Origin images headers include Cache-Control settings but these header are not being transfered to AWS. 源图像标头包含Cache-Control设置,但这些标头未传输到AWS。 I have checked the AWS documentation and I think that my Cloudfront settings are correct: 我检查了AWS文档,并认为我的Cloudfront设置正确:

Settings Object Caching: Use Origin Cache Headers 设置对象缓存:使用原始缓存头

I have created a page where you can see the same image, loaded directly from its origin, and loaded by Cloudfront. 我创建了一个页面,您可以在其中看到相同的图像,该图像直接从其原始位置加载,并由Cloudfront加载。 As you can see, the second image doesn't include the Cache-Control header setting: 如您所见,第二个图像不包含Cache-Control标头设置:

https://www.fanaticguitars.com/cache-control-test.php https://www.fanaticguitars.com/cache-control-test.php

Any suggestion? 有什么建议吗?

Thank you. 谢谢。

The misconfiguration is on your server, not on CloudFront. 配置错误是在您的服务器上,而不是在CloudFront上。

If I connect to your www server but then lie to it and tell it I'm asking for img rather than www by setting the HTTP Host: header (which is what CloudFront is doing when it fetches content, if you have the Host: header whitelisted in the cache behavior), your server doesn't return Cache-Control headers in this case even though it does (twice!) when the request is targeted to www . 如果我连接到您的www服务器,但随后撒谎并告诉它,我通过设置HTTP Host:标头(而不是www来询问img (如果拥有Host:标头,则CloudFront在获取内容时正在执行此操作在缓存行为中列入白名单),即使请求以www为目标, 服务器也不会(两次!) 在这种情况下不返回Cache-Control标头

This is a connection to your server, not to CloudFront: 这是到服务器的连接,而不是到CloudFront的连接:

$ curl -v https://www.fanaticguitars.com/v2/avatar.png -H 'Host: img.fanaticguitars.com' > /dev/null

> GET /v2/avatar.png HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Accept: */*
> Host: img.fanaticguitars.com
>
< HTTP/1.1 200 OK
< Server: nginx
< Date: Thu, 09 Mar 2017 16:49:31 GMT
< Content-Type: image/png
< Content-Length: 9915
< Last-Modified: Wed, 01 Mar 2017 21:46:59 GMT
< Connection: close
< Accept-Ranges: bytes
<
* Closing connection #0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 AWS Cloudfront 中如何添加缓存控制? - In AWS Cloudfront how to add cache-control? AWS Elastic Beanstalk / S3 / CloudFront缓存控制标头 - AWS Elastic Beanstalk / S3 / CloudFront Cache-Control Header 要从AWS CloudFront删除缓存控制标头吗? - Remove Cache-Control headers from AWS CloudFront? CloudFront是否在来自原点的错误响应(例如503)中使用Cache-Control标头? - Does CloudFront make use of Cache-Control headers in error responses (e.g. 503) from the origin? 来自 AWS CloudFront 的外部 Next.js 图像的缓存控制策略对于 Google Lighthouse 效率不高 - Cache-Control policy for external Next.js Image coming from AWS CloudFront is not efficient for Google Lighthouse 如何在亚马逊云端设置 Cache-Control Header? - How to set Cache-Control Header in amazon cloudfront? Amazon Cloudfront Cache-Control:no-cache 标头在 24 小时后无效 - Amazon Cloudfront Cache-Control: no-cache header has no effect after 24 hours 将缓存控制元数据添加到AWS Elastic Transcoder输出 - Add Cache-Control Metadata to AWS Elastic Transcoder Output S3 / CloudFront,提供标题为“Cache-Control:max-age = 365000000,immutable”的所有文件 - S3/CloudFront, serve all files with header “Cache-Control: max-age=365000000, immutable” Service Workers、AWS CloudFront 和 Access-Control-Allow-Origin - Service Workers, AWS CloudFront and Access-Control-Allow-Origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM