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
gefragt vor 2 Jahren751 Aufrufe
1 Antwort
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
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen