0

我正在尝试配置 HAProxy 后端以与 Google-CDN 一起使用我看到我总是到达 HAProxy 后端并且缓存总是 MISS

这是关于标头的 google-cdn 请求: https ://cloud.google.com/cdn/docs/caching#cacheability

这是我的 HAProxy 后端配置(我尝试了多组标头配置,但从未得到 HIT):

    http-response set-header Cache-Control public;max-age=31536000
    http-response set-header Content-Length 260113322
#    http-request add-header Cache-Control public;max-age=31533000
#    http-request add-header Content-Length 26012101001

当我在浏览器中请求对象时,这些是 req\res 标头:

响应标头

alt-svc: clear
cache-control: public;max-age=31536000
content-length: 260113322
content-type: application/javascript; charset=utf-8
date: Thu, 05 Sep 2019 07:56:59 GMT
etag: W/"47e80-NwQR7oXLIZF+J1AAVu9L0mv54I4"
status: 200
vary: Accept-Encoding
via: 1.1 google

请求标头

:authority: sapix-stg.example.net
:method: GET
:path: /bb/client/SX1234/main.js
: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
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 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36

谢谢

4

2 回答 2

1

您的Cache-Control响应标头格式错误。这些值用逗号(以及约定包含的可选空格)分隔——而不是分号。

http-response set-header Cache-Control "public, max-age=31536000"

引号被 HAProxy 解析器吸收。也有效:

(没有空间)

http-response set-header Cache-Control public,max-age=31536000

(空间逃脱)

http-response set-header Cache-Control public,\ max-age=31536000

通常不需要添加Content-Length代理。如果您的源服务器没有自动设置Content-LengthTransfer-Encoding在响应中设置,那么您的服务器应该被修复、升级或更换。

于 2019-09-05T15:57:57.433 回答
0

这可能是因为您的响应包含“Vary”标头。HAPoxy他们不缓存那种类型的响应。

于 2022-01-22T10:36:55.863 回答