具有自定义源重定向请求的 CloudFront 分配

编程入门 行业动态 更新时间:2024-10-26 04:27:45
本文介绍了具有自定义源重定向请求的 CloudFront 分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我设置了一个 CloudFront 分配以使用 自定义源 - 我客户的网络服务器 (www.mydomain).

当我加载我的网页并检查 Chrome 网络检查器的网络选项卡时,资产显示为来​​自源服务器 (www.mydomain) 和发起者"列将 CloudFront URL 显示为重定向.我认为这意味着 CloudFront 正在将资产请求重定向到我的源服务器,这几乎违背了目的.

当我设置分发时,我将 TTL 保留为默认值,我认为这意味着 24 小时.

如果我使用 S3 存储桶作为源而不是 Web 服务器,则资产会按预期直接从 CloudFront 加载.

解决方案

如果您在资产的 URL 中看到您自己的服务器域,则意味着 CloudFront 在去获取资产并正在为该资产提供服务时收到了重定向响应重定向作为缓存的结果.这绝对不是你想要的.

我遇到了一个类似的问题,在看到这篇文章的一个答案后我解决了这个问题:

Magento - Amazon Cloudfront CDN 和缓存

我正在从 domain 重定向到 www.domain,而 CloudFront 正在缓存并返回该重定向.您可能会在 http/https 重定向中看到相同的内容.

如果您正在执行 HTTP -> HTTPS 重定向,您有两个选择:您可以将资产作为 HTTP 提供给 CloudFront,或者让 CloudFront 作为 HTTPS 请求它们.要执行后者,您需要将 CloudFront 源配置为匹配查看器".这意味着,如果查看器使用 HTTPS,CloudFront 也将使用.如果用户使用 HTTP,CloudFront 会以 HTTP 形式请求,返回它从您的服务器收到的 HTTPS 重定向,然后客户端会以 HTTPS 的形式重新发出请求.

在我们的例子中,资产本身不需要在运行中受到保护.重要的是它们从 CloudFront 作为 HTTPS 提供,以便用户的浏览器看到所有 HTTPS 内容.因此,在我们的案例中,没有必要将资产作为 HTTPS 提供给 CloudFront.无论它如何从我们的服务器获取内容,CloudFront 都会在响应时匹配查看器的协议.

I set up a CloudFront distribution to work with a Custom Origin - my client's web server (www.mydomain).

When I load my webpage and check the Network tab of the Chrome web inspector, the assets are shown as coming from the origin server (www.mydomain), and the "Initiator" column shows the CloudFront URL as a redirect. I take that to mean that CloudFront is redirecting the asset request to my origin server, which pretty much defeats the purpose.

When I set up the distribution, I left the TTL at the default value, which I believe means 24 hours.

If I use an S3 bucket as the origin instead of a web server, the assets load directly from CloudFront as expected.

解决方案

If you see your own server domain in the URL for the asset, it means that CloudFront received a redirect response when it went to fetch the asset and is serving that redirect as the cached result. This is definitely not what you want.

I had a similar problem that I solved after seeing one of the answers on this post:

Magento - Amazon Cloudfront CDN and Caching

I was redirecting from domain to www.domain and CloudFront was caching and returning that redirect. You would probably see the same thing with an http/https redirect.

If you're doing an HTTP -> HTTPS redirect, you have two options: You can either serve the assets to CloudFront as HTTP or make CloudFront request them as HTTPS. To do the latter, you would need to configure your CloudFront origin to "Match Viewer." That means that if the viewer is using HTTPS, CloudFront will also. If the user is using HTTP, CloudFront would request in HTTP, return the HTTPS redirect it received from your server, and the client would then re-issue the request as HTTPS.

In our case, the assets themselves do not need to be protected in-flight. It is only important that they are served from CloudFront as HTTPS so the user's browser is seeing all HTTPS content. So, in our case, it is not necessary to serve the assets to CloudFront as HTTPS. Regardless of how it fetches the content from our server, CloudFront will match the viewer's protocol when it responds.

更多推荐

具有自定义源重定向请求的 CloudFront 分配

本文发布于:2023-11-02 08:02:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551829.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   重定向   分配   CloudFront

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!