1

我有一个在 EC2、ALB、Cloudfront 和清漆上设置的 wordpress 网站。在 chrome 开发工具栏上,我遇到了一个问题,即 cloudfront 缓存对于文档/html 类型总是未命中,但对于 js、css、png 等静态文件是命中的。我在响应标头(仅适用于文档类型)上发现了一个 cookie (我相信)像这样来自 ALB:

set-cookie: AWSALB=U5AWJwh/v3MaAYRDCdFicDCuiWi9Fy14fiegh0DG2UwTIq5zToBRCrpUO7nqqj2mI5XRcbu9pINYxv0XhmjVC5T2swGCP8RzeAJLrOwy3NLPRB/nJSJD/ng5Iy/0; Expires=Thu, 12 Dec 2019 03:50:07 GMT; Path=/

我试图在云端缓存行为设置上解决这个问题,然后我设置:

Whitelist Cookies:  AWSALB=*

等待几分钟让云端缓存刷新后,我尝试加载网站,但我仍然收到 x-cache 的响应“MISS”。如何解决这个问题呢。这是 MISS 缓存的响应和请求标头:

General:
Request URL: https://yyy.com/
Request Method: GET
Status Code: 200 
Remote Address: zzz:443
Referrer Policy: no-referrer-when-downgrade

Response Header:
accept-ranges: bytes
age: 0
cache-control: max-age=3299, public
content-encoding: gzip
content-length: 39955
content-type: text/html; charset=UTF-8
date: Thu, 05 Dec 2019 01:21:07 GMT
etag: "92d49bdbffc17d570120a667c34465a6"
expires: Thu, 05 Dec 2019 02:16:06 GMT
last-modified: Thu, 05 Dec 2019 01:16:06 GMT
link: <https://yyy.com/wp-json/>; rel="https://api.w.org/"
link: <https://yyy.com/>; rel=shortlink
pragma: public
server: nginx/1.16.1
set-cookie: AWSALB=7zzIXUQ/O9X6+vce8GWOs1x1ES9/nr7r5/Hc06xmWL5GDMVLeaUJututZeBJf7TVIHdbXmOZgAhvYtkQva9y/bFPi2EPdn3j5MqqbSOiPs+qS+9adILQ95csWH+/; Expires=Thu, 12 Dec 2019 01:21:07 GMT; Path=/
status: 200
vary: Accept-Encoding
via: 1.1 varnish, 1.1 f92e2b771ebc524db2f478f72162e565.cloudfront.net (CloudFront)
x-amz-cf-id: EmCMRJ9cQ6zs0N4tvHAEOZxC1l6vYMIqBTA6hTVlqsxuKj275VRNLQ==
x-amz-cf-pop: SIN5-C1
x-cache: Miss from cloudfront
x-varnish: 339894892

Request Header:
:authority: yyy.com
:method: GET
:path: /
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9,id;q=0.8
cache-control: no-cache
pragma: no-cache
sec-fetch-mode: navigate
sec-fetch-site: none
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36

这是 HIT 缓存的响应和请求标头:

General:
Request URL: https://yyy.com/wp-content/cache/minify/db66e.css
Request Method: GET
Status Code: 200 
Remote Address: zzz:443
Referrer Policy: no-referrer-when-downgrade

Response Header:
accept-ranges: bytes
age: 630787
cache-control: max-age=31536000, public
content-encoding: gzip
content-length: 100500
content-type: text/css; charset=utf-8
date: Wed, 27 Nov 2019 18:08:00 GMT
etag: "pub1574872585;gz"
expires: Thu, 26 Nov 2020 18:07:58 GMT
last-modified: Wed, 27 Nov 2019 16:36:25 GMT
pragma: public
server: nginx/1.16.1
status: 200
vary: Accept-Encoding
via: 1.1 varnish, 1.1 f92e2b771ebc524db2f478f72162e565.cloudfront.net (CloudFront)
x-amz-cf-id: -8otMvG_QhBrVBVH8HD0AuzsTwny_o7QkDuQnZnHHqcmqriLuAw_Lw==
x-amz-cf-pop: SIN5-C1
x-cache: Hit from cloudfront
x-varnish: 1158322228

Request Header:
:authority: yyy.com
:method: GET
:path: /wp-content/cache/minify/db66e.css
:scheme: https
accept: text/css,*/*;q=0.1
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9,id;q=0.8
cache-control: no-cache
cookie: AWSALB=7zzIXUQ/O9X6+vce8GWOs1x1ES9/nr7r5/Hc06xmWL5GDMVLeaUJututZeBJf7TVIHdbXmOZgAhvYtkQva9y/bFPi2EPdn3j5MqqbSOiPs+qS+9adILQ95csWH+/
pragma: no-cache
referer: https://yyy.com/
sec-fetch-mode: no-cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36

谢谢。

4

0 回答 0