0

我正在尝试为多个服务设置负载均衡器。每个服务都有自己的外部 ELB。由于 CORS,我不想为 service1、service2 ... 使用子域,并且想摆脱 OPTIONS 请求。

我为此使用 CloudFront 和行为。网站是一个SPA。

https://beta.myapp.com  - main page → S3
https://beta.myapp.com/api/service1/v1/* → service1 ELB
https://beta.myapp.com/api/service2/v1/* → service2 ELB

当我在没有任何转发的情况下为 service1 设置行为时,我的服务出现错误 - 401 Unauthorized。因为它依赖 cookie 进行未经授权。

在我设置后Forward Cookies-AllWhitelist myapp-api-token*- 我开始收到 404 错误并还原到我的错误静态页面。我在服务日志中没有看到我的服务被请求。

其他选项喜欢Cache Based on Selected Request Headers并且Query String Forwarding and Caching根本不影响任何东西。

  • 可能是什么问题?
  • 如何在 CloudFront 中调试或记录路由?

提到 cookie 是 Secured 和 HttpOnly 可能很重要。

饼干的例子:

cookie: myapp-api-token=eyJraWQiOiJyRlZYTGpCRVJJRDZ6MVVpSVpDaENVQVczNlRua0FMb3dDQzlHMnBmcG1VPSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJiZGYzNjNiOC1jMWM3LTQzNDMtOTc2My0zOTk3ZDFiNTYxZWQiLCJjdXN0b206a2V5U3BlYyI6IkFFU18yNTYiLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV9FRzlwSjRsb0giLCJjdXN0b206ZW5jcnlwdGVkUGFzc3dvcmQiOiJBUUVDQUhqa3BxM0pmUzNId0c1XC92cTNicHY4TUdjaWhJZ0hReVFsQk1OY09Ea1JZOHdBQUFIb3dlQVlKS29aSWh2Y05BUWNHb0dzd2FRSUJBREJrQmdrcWhraUc5dzBCQndFd0hnWUpZSVpJQVdVREJBRXVNQkVFREo5b2hwYSt2WnNMdXBQXC9sQUlCRUlBM3RCOUFrRWhjR0hJSFhiSitnXC9DRUZ3REljc3EzaEpBTVlxTVZmS2g1ZmZIVW9BMGp2YzU2NzJGcEpjK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rcLxnDLL3XjIqlKLj9rCsKOrEIznwZLsCfrBjQBZE8mq9VHUaajFpochyaM1rjL9J8q9-tZTcHnE1ryrLNLvW_vtS1WLic1WVTw9TkCQJCc1HT3KyI-mmqc4fg7Vyw7_RC3DcbiV7Rw
4

1 回答 1

0

I guess you're using "Cache behavior" with "Path Pattern" to route user request to Origin? If that so, check the order of your behavior, as you list in your question, you put the * pattern in the first order, mean all request will be route to S3 which will cause 404 not found error since your S3 site doesn't have that URL path.

于 2019-04-10T07:46:35.450 回答