如何解决 Google Cloud CDN 和 Compute Engine 的 CORS 问题

How to solve CORS issue for Google Cloud CDN & Compute Engine

我创建了一个 Compute Engine - VM 并安装了多个网站。 此外,我还创建了网络服务 - 负载平衡 - 后端配置:创建后端服务并加入与上面相同的虚拟机的实例组。 - 创建了 Cloud CDN 并配置了 SSL 证书。

网站是https://united-athle.hk/ CDN域名为https://cdn.ua.sugarproject.com

当我访问该网站时,出现了以下 CORS 问题 对“https://cdn.ua.sugarproject.com/wp-content/plugins/onesignal-free-web-push-notifications/sdk_files/manifest.json.php?gcm_sender_id=' from origin 'https://united-athle.hk”处的资源的访问已被 CORS 策略阻止:请求的资源上不存在 'Access-Control-Allow-Origin' header。

我已阅读Cross-origin资源共享(CORS), https://cloud.google.com/storage/docs/cross-origin 但不太确定 how-to 配置。我的存储在 VM 引擎中。

有人知道吗?

一种选择是在您的 VM 上配置 Web 服务器软件 运行,以在其响应中包含 Access-Control-Allow-Origin header。例如,包含 Access-Control-Allow-Origin: https://united-athle.hk header 将允许来自 https://united-athle.hk/. https://enable-cors.org/server.html 的 cross-origin 请求包含有关如何为各种 Web 服务器软件执行此操作的信息。

或者,您可以通过一个域名为网站的两个部分提供服务,从而无需 cross-origin 请求。