如何实现到外部的重定向 url

How to Implement a redirect to an external url

动机:我们正在维护一个本地托管的网站 https://customerRelationsSite.com

此网站即将消失,我们想创建一个 URL 重定向到具有以下用例的其他网站

   location ~ ^/path/(?<section>.*) {
             resolver 8.8.8.8;
             proxy_pass https://othersite/newPath/$section$is$
           }

   location ~ ^/eula/prodmanager/(?<section>.*) {
             resolver 8.8.8.8;
             proxy_pass https://domain.salesforce.com/eula/prod/myapp/$section$is$
           }

您会考虑哪些选项? 或者还有其他可用的最佳选择吗?

您可以使用静态 S3 存储桶执行此操作:

https://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html

正如您所说,只需将域指向(通过您喜欢的任何 DNS 方式)一个否则为空的 S3 存储桶,然后按照上面的说明设置重定向。

为了奖励积分,您也可以安装自定义 404 页面等:

 <RoutingRules>
    <RoutingRule>
    <Condition>
      <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
    </Condition>
    <Redirect>
      <ReplaceKeyWith>404.html</ReplaceKeyWith>
    </Redirect>
    </RoutingRule>
  </RoutingRules>

这通常避免了托管 haproxy 个实例或 Linux 个实例的任何复杂性 - 并且具有成本效益并且 recommended by AWS themselves.

(顺便说一句 - 404 技巧非常适用于静态托管在 S3 存储桶中的单页应用程序。将所有 404 URL 重定向回 index.html - 让 SPA 完成剩下的工作!)