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
asked 2 years ago730 views
1 Answer
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
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions