简体   繁体   English

将 HAProxy 配置为 Google-CDN 后端

[英]Configuring HAProxy as Google-CDN backend

I'm trying to configure an HAProxy backend to work with Google-CDN I see that I always get to the HAProxy backend and the cache is always MISS我正在尝试配置一个 HAProxy 后端以与 Google-CDN 一起使用我看到我总是到达 HAProxy 后端并且缓存总是 MISS

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

and this is my HAProxy backend configurations (I've tried multiple sets of headers configuration, but never got an HIT):这是我的 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

when I'm requesting the object in the browser these are the req\\res headers:当我在浏览器中请求对象时,这些是 req\\res 标头:

Response Headers响应标头

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

Request Headers请求标头

: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

Thanks谢谢

Your Cache-Control reaponse header is malformed. 您的Cache-Control响应头不正确。 The values are separared with a comma (and optional whitespace included by convention) -- not a semicolon. 这些值用逗号(以及约定中包括的可选空格)分隔-而不是分号。

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

The quotes are absorbed by the HAProxy parser. 引号由HAProxy解析器吸收。 Also valid: 也有效:

(no space) (没有空间)

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

(space escaped) (逃脱的空间)

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

There should normally be no need to add Content-Length in the proxy. 通常,无需在代理中添加Content-Length If your origin server isn't automatically setting either Content-Length or Transfer-Encoding in the response, then your server should be fixed, upgraded, or replaced. 如果您的原始服务器没有在响应中自动设置Content-LengthTransfer-Encoding ,那么您的服务器应该是固定的,升级的或更换的。

It might be because your response contains "Vary" header.这可能是因为您的响应包含“Vary”标头。 HAPoxy says that they don't cache that type of responses. HAPoxy 他们不缓存那种类型的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM