[英]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.