简体   繁体   English

如何将域指向从Amazon S3服务静态站点? (不是子域)

[英]How to point a domain to serve static site from Amazon S3? (not sub-domain)

I see several people describing how to do this for a custom domain with sub-domain but no one talking about how to do it without one. 我看到一些人描述了如何针对具有子域的自定义域执行此操作,但是没有人谈论没有它的情况下如何执行此操作。

Example: Setting foobar.com and www.foobar.com to point to my Amazon S3–hosted site 示例: 将foobar.com和www.foobar.com设置为指向我的Amazon S3托管站点

I personally do not want the www prefix. 我个人不希望使用www前缀。 Is there no way to make this happen? 有没有办法做到这一点? I seems crazy that Amazon would set it up to allow static sites and custom domains, then lock it down to prefixed domains? 亚马逊将其设置为允许静态站点和自定义域,然后将其锁定为带前缀的域,我似乎感到疯狂。

Thanks in advance, 提前致谢,

For historical reasons any URL needs to resolve to a subdomain, which you already know how to handle: Create a CNAME record with your DNS provider, pointing www to your S3-hosted subdomain. 由于历史原因,任何URL都需要解析为一个子域,您已经知道如何处理该子域:与DNS提供商创建CNAME记录,将www指向S3托管的子域。 There are details to get right, described nicely elsewhere. 有正确的细节,在其他地方很好地描述了。

You nevertheless want to support users who, charmed that their browsers will autocomplete http:// and .com and such, want to type a naked domain domain.com , and have it automatically complete to your default subdomain such as www.domain.com . 但是,您仍然希望支持那些希望自己的浏览器能够自动完成http://.com类的用户,并希望输入一个裸域domain.com并将其自动完成到您的默认子域(例如www.domain.com

The easiest way to accomplish this is to use www as your default subdomain, and point your DNS provider's A record at wwwizer.com ( 174.129.25.170 ). 最简单的方法是使用www作为默认子域,并将DNS提供商的A记录wwwizer.com174.129.25.170 )。 They automatically redirect any naked domain to the same domain with www in front. 他们会自动将任何裸域重定向到前面带有www的相同域。

You get fastest turnaround on development, and your visitors get fastest DNS resolution, if you use Amazon Route 53 to provide your DNS services. 如果您使用Amazon Route 53提供DNS服务,则开发最快的周转时间和访问者的DNS解析速度最快。 Route 53 can point its A records to wwwizer.com . 路线53可以将其A记录指向wwwizer.com However, you may want to create a micro Amazon EC2 instance, and start programming it. 但是,您可能要创建一个微型Amazon EC2实例,然后开始对其进行编程。 In the '50s everyone rebuilt their own cars. 在50年代,每个人都改造了自己的汽车。 In the '80s everyone pushed a shopping cart down the aisle at Fry's, and built their own computer. 在80年代,每个人都将购物车推到Fry's的过道上,并建造了自己的计算机。 Now, you want to be able to build your own computer in the cloud, for many reasons you will discover with time, and Amazon EC2 is best choice. 现在,由于许多原因,您希望能够随着时间的推移在云中构建自己的计算机,而Amazon EC2是最佳选择。 For now, your cloud computer will simply handle naked domains for you. 目前,您的云计算机将只为您处理裸域。 Later, email, generating the static site, ... 稍后,通过电子邮件发送,生成静态站点,...

Install the Apache web server (the A in LAMP; a LAMP server will do the trick), and configure a virtual host for each of your domains. 安装Apache Web服务器(LAMP中的A; LAMP服务器将解决问题),并为每个域配置虚拟主机。 Then point an elastic IP address at your EC2 instance, and update Route 53 to have your A record point to this elastic IP address. 然后将一个弹性IP地址指向您的EC2实例,并更新Route 53以使您的A记录指向该弹性IP地址。 Amazon doesn't support having multiple elastic IPs pointing to the same EC2 instance, but you can provide the same elastic IP to multiple domain A records, and have Apache resolve this within your EC2 instance. Amazon不支持具有指向同一EC2实例的多个弹性IP,但是您可以为多个域A记录提供相同的弹性IP,并让Apache在您的EC2实例中解决此问题。

This takes some fiddling and experimenting, as there's lots of conflicting advice on the details. 这需要一些摆弄和试验,因为在细节上有很多相互矛盾的建议。 I used the ami-ad36fbc4 instance image (US East, 64 bit EBS-backed Ubuntu 10.04 LTS), as I'm familiar with Ubuntu, there's plenty of online help with Ubuntu, and this image will be supported for years. 我使用了ami-ad36fbc4实例映像(美国东部,由64位EBS支持的Ubuntu 10.04 LTS),因为我熟悉Ubuntu,Ubuntu有很多在线帮助,并且该映像将得到多年支持。 I edited /etc/apache2/httpd.conf to have the contents 我编辑了/etc/apache2/httpd.conf以包含内容

NameVirtualHost *

<VirtualHost *>
ServerName first.net
Redirect permanent / http://www.first.net/
</VirtualHost>

<VirtualHost *>
ServerName second.net
Redirect permanent / http://www.second.net/
</VirtualHost>

then checked for errors using 然后使用检查错误

sudo /usr/sbin/apache2ctl configtest

then restarted the Apache server using 然后使用重新启动Apache服务器

sudo /etc/init.d/apache2 restart

Apache is standard across Linux flavors, but the details such as file locations may vary, eg /etc/apache2/httpd.conf could be /etc/httpd.conf . Apache是​​Linux风格的标准配置,但文件位置等详细信息可能有所不同,例如/etc/apache2/httpd.conf可以是/etc/httpd.conf For example, it might be necessary put a Listen 80 in httpd.conf , but Apache throws an error if that command was already somewhere else. 例如,可能有必要在httpd.conf放置一个Listen 80 ,但是如果该命令已经在其他地方,则Apache会引发错误。 So read web instructions with a grain of salt, and be prepared to Google any error messages. 因此,请仔细阅读网络说明,并准备向Google发送任何错误消息。

As I'd already been using Amazon Route 53 for days to point to wwwizer.com , this worked immediately once I updated Route 53 to point to my elastic IP. 因为我已经使用Amazon Route 53数天来指向wwwizer.com ,所以当我更新Route 53以指向我的弹性IP时,这立即起作用。 Before switching to Route 53, each change took days for me to verify, as the information propagated across the web. 在切换到Route 53之前,随着信息在网络上的传播,每次更改都需要我花费几天的时间进行验证。 Once everyone knows to look to Amazon, Amazon can propagate its internal changes much more quickly. 一旦所有人都知道要使用Amazon,Amazon便可以更快地传播其内部更改。

Unfortunately you can not point foobar.com to an Amazon S3 bucket and the reason for this has to do with how DNS works. 不幸的是,您无法将foobar.com指向Amazon S3存储桶,其原因与DNS的工作方式有关。

DNS does not allow the root of a domain (called zone apex) to point to another DNS name (you can not have foobar.com set up as a CNAME / only subdomain.foobar.com can be a CNAME) DNS不允许域的根(称为区域顶点)指向另一个DNS名称(您不能将foobar.com设置为CNAME /只有subdomain.foobar.com可以是CNAME)

Since this question was asked things have changed. 自从提出这个问题以来,情况已经改变。 It is now possible to host your site on S3 with a root domain. 现在可以在具有根域的S3上托管您的站点。

Instead of just having one bucket named "www.yourserver.com", you have to create another bucket with the nude (root) domain name, eg "yourserver.com". 您不仅要创建一个名为“ www.yourserver.com”的存储桶,还必须创建另一个具有裸(根)域名的存储桶,例如“ yourserver.com”。

After that you will have to use Amazon's DNS service Route 53. Create an A record for the nude domain and a CNAME for the "www" hostname. 之后,您将必须使用Amazon的DNS服务Route53。为裸域创建A记录,为“ www”主机名创建CNAME。

Note that you will need to move the domain management of your domain to Amazon Route 53 completely. 请注意,您将需要将域的域管理完全移至Amazon Route 53。

See for the detailled walk-through here: http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html 请参阅此处以获取详细的演练: http : //docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM