我如何排除 Amazon Cloudfront 中的 URL?

How can I exclude URLs within Amazon Cloudfront?

我计划使用 Amazon Cloudfront CDN,但有一个 URL 我需要排除。这是一个动态的 URL(包含一个查询字符串)。

例如,我想 store/cache 我网站上的每个页面,除了:

http://www.mypage.com/do-not-cache/?query1=true&query2=5

编辑 - 这就是使 'objects' 无效的作用吗?如果是,请举例说明。

谢谢

冒着帮助您解决错误问题的风险,我应该指出,如果您将 CloudFront 配置为将查询字符串转发到源服务器,那么响应将针对整个 URI 进行缓存——也就是说,针对路径 + query-string -- 不反对路径,只是,所以...

/dynamic-page?r=1
/dynamic-page?r=2
/dynamic-page?r=2&foo=bar

...就 CloudFront 而言,将是三个 不同的 "pages"。除非查询字符串 相同.

,否则它永远不会为来自缓存的请求提供服务

If you configure CloudFront to forward query strings to your origin, CloudFront will include the query string portion of the URL when caching the object. [...]

This is true even if your origin always returns the same [content] regardless of the query string.

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/QueryStringParameters.html

因此,实际上没有必要明确和故意避免在此页面上进行缓存。如果 CloudFront 配置为转发查询字符串,正确的行为应该是自动的。

此外,当然,如果您的源服务器在响应中设置 Cache-Control: private, no-cache, no-store 或类似设置 headers,CloudFront 和浏览器都不应该缓存响应。

但是,如果您非常坚持将 CloudFront 明确配置为不缓存此页面,请使用 path pattern matching /do-not-cache*, and configure CloudFront to forward all of the request headers to the origin 创建一个新的缓存行为,它会禁用与该路径模式匹配的页面请求的缓存。