Cloudfront和EC2 [英] Cloudfront and EC2

查看:134
本文介绍了Cloudfront和EC2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在EC2实例之前设置Cloudfront?
我有兴趣让用户访问Cloudfront URL,而不是EC2来源。

How do you setup Cloudfront in front of an EC2 instance? I'm interested in having users hit the Cloudfront url rather than the EC2 origin.

因此,您不必访问ec2-52-64-xxx-xxx。 ap-southeast-2.compute.amazonaws.com用户会访问d111111abcdef8.cloudfront.net。

So instead of hitting ec2-52-64-xxx-xxx.ap-southeast-2.compute.amazonaws.com users would hit d111111abcdef8.cloudfront.net.

我的目的是通过减少流量和CPU负载来节省托管费用。在EC2实例上,同时为海外用户提供了更快的加载时间。

My intention is to save money on hosting by reducing the traffic and CPU load on the EC2 instance, while providing overseas users with faster load times.

我是否只需将DNS指向Cloudfront网址而不是EC2来源?

Would I just point my DNS to the Cloudfront url instead of the EC2 origin?

推荐答案


我是否只需将DNS指向Cloudfront网址而不是EC2来源?

Would I just point my DNS to the Cloudfront url instead of the EC2 origin?

相当多。

从技术上讲,您不会将DNS指向URL,而是将其指向主机名或IP地址,这与CloudFront有所不同。

Technically, you don't point DNS to a URL, you point it to a hostname or to an IP address, which is done a little differently with CloudFront.

首先,尽管...在CloudFront分发设置中,您需要在备用域名框中配置CloudFront期望浏览器发送的所有主机名。

First, though... in the CloudFront distribution settings, you need to configure any hostnames that CloudFront should expect to see sent by the browser, in the "alternate domain names" box.

对于来源,输入 ec2 -...- compute.amazonaws.com 主机名。

For the origin, enter the ec2-...-compute.amazonaws.com hostname.

这时,在10到15分钟后,访问由CloudFront分配的URL应该会将您带到服务器。

At this point, after 10-15 minutes, visiting the CloudFront-assigned URL should take you to your server.

下一步...如果您的DNS托管在Route 53中,那么您将转到托管区域并为这些主机名创建新的 A记录,并设置别名到是,这将导致使用CloudFront分布填充目标框,然后选择该位置并保存记录。

Next... if your DNS is hosted in Route 53, then you'd go to the hosted zone and create new "A" records for those hostnames, setting "Alias" to "Yes," which should cause the targets box to be populated with the CloudFront distribution, which you would then select, and save the record.

如果您的DNS不是由Route 53托管的,您可以在DNS中创建 CNAME 记录,指向分配给CloudFront分配的主机名,例如 jozxyqkexample.cloudfront.net 。这里的要点是,您不能使用域的顶点/根来执行此操作,因为 CNAME 在那里无效……所以www.example .com将起作用,但example.com将不起作用。这是DNS的局限性,唯一的解决方法是对DNS使用Route 53,因为它与CloudFront内部集成(因此,上面提到的别名记录使用内部查找而不是外部引用,例如CNAME) )。

If your DNS isn't hosted by Route 53, you would instead create CNAME records in DNS, pointing to the hostname assigned to the CloudFront distribution, e.g. jozxyqkexample.cloudfront.net. The catch, here, is that you can't do this with the apex/root of your domain, because a CNAME isn't valid there... so www.example.com would work, but example.com will not. This is a limitation of DNS, and the only workaround is to use Route 53 for your DNS, because it has internal integration with CloudFront (hence the "Alias" records, mentioned above, which use internal lookups rather than external referrals, like a CNAME).

您可能还需要配置CloudFront将 Host 标头转发回原始服务器;否则,当请求到达时,HTTP请求中提供给服务器的主机名将不是您的域名,而是您配置为原始主机的主机名。

You may also want to configure CloudFront to forward the Host header back to the origin server; otherwise when the request arrives, the hostname presented to your server in the HTTP requests will not be your domain name, and instead will be the hostname you configured as the origin host.

请确保通过CloudFront连接时,服务器不会将您重定向回EC2主机名或IP(浏览器中的地址栏会更改,如果确实如此,如果发生这种情况,您将需要修复Web服务器的配置。)

Be sure, when you connect through CloudFront, that the server doesn't redirect you back to the EC2 hostname or IP (the address bar in the browser will change, if it does, and you'll want to fix your web server's config if that happens).

这篇关于Cloudfront和EC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆