Google Cloud CDN不会缓存https页面,因为它们具有Vary标头x-forwarded-proto

问题描述

似乎我无法在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缓存此内容,则需要查看添加标头的原因并找到一种删除它的方法。我找到了几篇您可以阅读的文章:

您将必须找到一种解决方案来根据您的部署删除此标头。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...