سؤال

I have a mostly static website. Almost everything points to static content including the root url, except for two calls to the API, so it looks something like this

www.example.com <- static content on s3

www.example.com/call_1 <-- call to api on EC2 instance, only made from javascript

www.example.com/call_2 <--- call to api, only made from javascript

www.example.com/* <-- static content on s3

As I understand it I can't configure a DNS to route depending on path can I? Should I create a sub-domain that redirect calls to the EC2 instance: api.example.com?

Adding the overhead of another layer on the EC2 instance to redirect requests doesn't seem like a good option to me. So if I can do it with sub-domains the better.

هل كانت مفيدة؟

المحلول

You are correct that DNS, by definition doesn't allow you to route based in path - the DNS server never sees that part of the http request.

Subdomains are definitely a possibility, although if these are ajax requests (as opposed to json-p) you will have to read up on CORS headers, which allow you to instruct the browser which cross origin ajax calls are permitted.

Another possibility would be to use cloudfront as a layer inbetween your end users and content. In cloudfront lingo you can setup different behaviours to route different paths to different origins, where origins can be s3 buckets, elastic load balancers or arbitrary ip addresses/hosts. This would also have the advantage that your s3 content would be cached closer to your end users.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top