fider icon indicating copy to clipboard operation
fider copied to clipboard

AWS load balancer appears to set the asset url

Open rickshawhobo opened this issue 8 years ago • 5 comments

Following the directions here https://getfider.com/docs/hosting-instance/ I set up the self hosted instance with docker and pointed a load balancer at it. I set up a health check on the load balancer to hit EC2 instance on port 9999 with the url /signup, so for example the AWS load balancer will fetch http://10.0.1.100:9999/signup every few minutes to make sure the host is still alive. The 10.0.1.100 is the private ip assigned to this EC2 instance. This is all pretty standard AWS stuff. The problem arrises when the load balancer fetches this url it appears to "stick" for all other consequent requests. Let's say your load balancer has a cname for your site at https://mydomain.com/signup. If we attempt to fetch this url from the browser we can see the javascript is being loaded from the internal ip

like this

  <script src="http://10.0.0.100:9999/assets/js/vendor.e2743ab2606f05522e7a.js" crossorigin="anonymous"></script>

Is this a bug? I see a suggestion for BASE_URL in https://github.com/getfider/fider/issues/253 that would help in this case

rickshawhobo avatar Dec 03 '18 22:12 rickshawhobo

Does AWS set X-Forwarded-Proto and X-Forwarded-Host when forwarding the request? Otherwise we use Host from the request.

goenning avatar Dec 03 '18 22:12 goenning

The load balancer health check does not set a X-Forwarded-Host because it is health checking on behalf of itself. So the host header is correctly set to the internal ip of the EC2, the real question is why does it "stick" for every subsequent requests that DO have that header? It seems to be cached forever once the base url is established by the first request? I got around this by restarting the app and quickly hitting the CNAME dns url in my browser before the load balancer health check kicks in.

You can see this bug by trying this locally

  1. Start the app with docker-compose up -d
  2. Fetch the signup url with a host header curl -H "Host: x.y.z" http://localhost:9999/signup
  3. Change the host header and fetch the same url again curl -H "Host: foo.bar.z" http://localhost:9999/signup

Observe the asset base url is still x.y.z

rickshawhobo avatar Dec 03 '18 22:12 rickshawhobo

Oh, you’re right. That does happen to Assets URL only, right? On first request we load the assets and generate the URL for the assets.. The full URL is cached and reused for all subsequent requests, which is clearly wrong.

Thanks for the report and repro steps!

goenning avatar Dec 03 '18 22:12 goenning

Thank you!

rickshawhobo avatar Dec 03 '18 22:12 rickshawhobo

This should now be fixed, can you confirm? It's available on master image.

goenning avatar Dec 04 '18 18:12 goenning