CloudFront 使用路径前缀重定向所有请求

问题描述 投票:0回答:1

我有一个向 API 服务器发出请求的静态网站。我使用 S3 托管这个静态页面,我想使用 CloudFront 将 api 调用重定向到 api 服务器。 api调用可以通过api的路径前缀来区分:

domain.com/index.html         s3/index.html
domain.com/js/index.js        s3/js/index.html
domain.com/api/request        api_server/api/request
domain.com/api/other/request  api_server/api/other/request

我目前设置了两个源点——一个用于我的 S3 存储桶的 S3 源点(正在运行)和另一个用于我的 api 服务器的自定义源点(它不工作)。

自定义原点设置如下:

Origin Domain Name: api_elb
Origin path: /

以及行为设置如下:

Precedence: 0
Path pattern: /api/*
Allowed HTTP Methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE
Forward Headers: all
Forward Query Strings: yes

这里是完整的回复:

> GET /api/logout HTTP/1.1
> Host: a0000aaaaaaaaa.cloudfront.net
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 502 Bad Gateway
< Content-Type: text/html
< Content-Length: 587
< Connection: keep-alive
< Server: CloudFront
< Date: Mon, 06 Jun 2016 19:37:45 GMT
< X-Cache: Error from cloudfront
< Via: 1.1 86f2bbfea57d6217ce2d279b84ca3743.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: A18vpnPPr0cWn5VuVirvvKc-wocC9OcXjNDHZm-PyvD3ONGcPmqmmg==
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
CloudFront wasn't able to connect to the origin.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: -u68y2nD9tuaxL_2MjSk3udA1r64v-K3xoGitKFYvd9Z48gB8ntnwg==
</PRE>
<ADDRESS>
</ADDRESS>

这个配置有什么问题?如何让 CloudFront 将这些请求转发到 API?它当前为所有 API 请求返回 502(错误网关)响应。

amazon-s3 amazon-cloudfront amazon-elb
1个回答
0
投票

看起来这是在这里回答的:

https://stackoverflow.com/a/23599450/2542922

我将 api_server.company.com 添加到备用域名。

© www.soinside.com 2019 - 2024. All rights reserved.