我有一个向 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(错误网关)响应。
• 如何将 CloudFront 日志流式传输到 CloudWatch
• Cloudfront 和 ELB 从 http 重定向到 https 的问题
• 托管在 Cloudfront 上的 Next.js 静态网站在其他端点的页面刷新时重定向到主页
• 使用 CloudFront 提供存储在 S3 中的静态内容/文件不起作用
• 在我的[email protected]源请求函数中,“事件”参数为空
• “无效或缺少别名 DNS TXT 记录。”使用 associate-alias 时,即使记录似乎存在
• AWS cli 查询以获取具有特定来源名称的云端“域名”
• 使用 java spring boot 应用程序从云前端等 cdn 服务器下载媒体
• 我可以直接从客户端浏览器上传图片到 CloudFront 吗?
• How to resolve Cloudfront CORS Error coming only from loader?