我正在尝试配置HAProxy后端以与Google-CDN一起工作,我发现我总是到达HAProxy后端,而缓存总是未命中
这是google-cdn关于头部的请求:https://cloud.google.com/cdn/docs/caching#cacheability
这是我的HAProxy后端配置(我已经尝试了多组标头配置,但从未成功):
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谢谢
发布于 2019-09-05 23:57:57
您的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-Length或Transfer-Encoding,那么您的服务器应该进行修复、升级或更换。
发布于 2022-01-22 10:36:56
这可能是因为您的响应包含"Vary“标头。HAPoxy says,他们不会缓存这种类型的响应。
https://stackoverflow.com/questions/57800888
复制相似问题