cdn:根据 ip 地理定位对特定来源的代理请求

cdn: proxy request to specific origin based on ip geolocation

我的服务有几个原始服务器,每个服务器都在不同的大陆。每个客户端请求都通过代理到这些服务器的 cdn。大约一半的请求是可缓存的,另一半则不是。哪个来源提供可缓存的响应并不重要,因为分布式 CDN 将处理来自最近的可能 POP 的响应,以便在未来(直到缓存过期)为这些请求提供响应。但是,对于不可缓存的响应,我希望离用户最近的源响应 CDN 正在代理的请求。

是否有某些 CDN 具有这样的功能,您可以通过它指定类似以下内容:"make a best effort to geocode the request based on ip, if the ip is from continent north america use noram.originfoo.com, if the ip is from continent europe use eu.originfoo.com, etc"?

也许架构应该改为 DNS 解析根据客户端 ip 选择 CDN 主机名,并且 CDN 具有不同的条目,其中一个区域特定的 CDN 主机名映射到一个源主机名。

您当然可以使用现有服务来执行此操作,AWS 肯定可以执行此操作。但是如果你想自己实现这个,你基本上需要通过他们的 IP 找到呼叫者的位置,并根据那个将 URL 发送到最近的位置。

看看fastly CDN solution. It uses varnish and allows for vcl rules to be used by the customer (see their docs)。 这是一个 guide 似乎在做你需要的事情:

Fastly allows you to change origin servers based on the user's geographic location. This is useful when you need to serve different content to users who are in different locations. For example, you could change origin servers to serve a restricted version of your website to users in a different country.