How to debug cloudfront behaviours not sending requests to correct origin?

0

I have two custom origins set up pointing to two different apps on Heroku, A and B.

I have three cache behaviours set up, all of which have caching disabled, and pass through all headers. In priority order:

Path pattern /v3 points to app A.
Path pattern /v3/* points to app A.
The default behaviour points to app B.

However, no matter what request I make (I've tried different variations on /v3, /v3/ and /v3/some-page, they are all routed to app B. App A is never reached.

I haven't been able to find any debugging info to help me figure out what's going on. Is there any? I turned on logs for the distribution, but these appear to be mainly access logs, and don't give any indication as to why a particular origin was chosen.

rosoll
질문됨 2년 전751회 조회
1개 답변
0

Figured it out:

I had the behaviours configured to pass through all headers (including the Host header). As Heroku uses global routing, app-a.herokuapp.com and app-b.herokuapp.com both resolve to the same thing, and Heroku uses the host header to route to the correct heroku app. So for e.g. curl app-a.herokuapp.com -H "Host: app-b.herokuapp.com" will make a request to app b, not app a.

For historical reasons, the overall domain name (let's call it example.com) had been "added" to heroku app b, so curl app-a.herokuapp.com -H "Host: example.com" would resolve to app b. Very confusing!

To fix this I created a custom cache policy that sent through all headers except the Host header, and changed the origins to add a hardcoded X-Forwarded-Host header set to the domain name, in this case example.com. Now the routing works, and the X-Forwarded-Host can be used by the two apps to know what host they've been accessed from. (One of them is Rails, which picks up the X-Forwarded-Host header automatically).

rosoll
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠