问题描述
似乎我无法在https请求中将Google Cloud CDN与GKE Ingress配合使用,因为Ingress控制器添加了vary http标头:x-forwarded-proto,该CDN不会缓存(请参见https://cloud.google.com/cdn/docs/caching#non-cacheable_content) 。我认为添加标头是正确的,因为它告诉提供内容的应用程序被请求为https。但是我不确定为什么CDN不会使用此标头缓存页面。
我丢失了什么东西吗?
当页面被请求为http并且 被缓存时的标头示例:
Age: 1713
Cache-Control: public,max-age=2000
content-encoding: gzip
Content-Length: 8503
Content-Type: text/html; charset=UTF-8
Date: Thu,13 Aug 2020 20:56:23 GMT
Server: Apache/2.4.38 (Debian)
vary: Accept-Encoding
Via: 1.1 google
X-Powered-By: PHP/7.4.9
当页面被请求为http且未缓存 时的标头示例:
alt-svc: clear
cache-control: public,max-age=2000
content-encoding: gzip
content-length: 8499
content-type: text/html; charset=UTF-8
date: Thu,13 Aug 2020 21:25:37 GMT
server: Apache/2.4.38 (Debian)
status: 200
vary: X-Forwarded-Proto,Accept-Encoding
via: 1.1 google
x-powered-by: PHP/7.4.9
非常感谢, 山姆
解决方法
您已经确认Cloud CDN由于此标头而不会缓存它。这是预料之中的。
关于添加的标头,如果您想使用Cloud CDN缓存此内容,则需要查看添加标头的原因并找到一种删除它的方法。我找到了几篇您可以阅读的文章:
- https://github.com/kubernetes/ingress-gce/issues/51
- https://serverfault.com/questions/912168/how-to-make-google-cloud-load-balancer-respect-the-received-x-forwarded-proto
- https://trac.nginx.org/nginx/ticket/1181
您将必须找到一种解决方案来根据您的部署删除此标头。