2013-08-18 32 views
22

我已经设置了Amazon S3来服务我的静态网站speakeasylinguistics.com。所有的DNS东西似乎工作正常,因为dig +recurse +trace www.speakeasylinguistics.com输出正确的DNS信息。亚马逊S3下载index.html而不是服务

但是当你使用visit the site in a browser端点时,index.html页下载,而不是被服务。我该如何解决?

我试过Chrome,Safari,FF。它发生在所有的人身上。我用Amazon's walkthrough上托管的自定义域为T.

+1

运行curl -I对文件返回:头中的Content-Disposition:attachment - 这就是导致问题的原因。我*认为*在文件的元数据中。 – dc5

+0

我解决了这个问题,指定上传HTML文件到S3时的元数据(content-type = text/html) – PedroHidalgo

回答

25

对您发布的URL运行卷曲-I给出以下结果:

curl -I http://speakeasylinguistics.com.s3-website-us-east-1.amazonaws.com/ 
HTTP/1.1 200 OK 
x-amz-id-2: DmfUpbglWQ/evhF3pTiXYf6c+gIE8j0F6mw7VmATOpfc29V5tb5YTeojC68jE7Rd 
x-amz-request-id: E233603809AF9956 
Date: Sun, 18 Aug 2013 07:58:55 GMT 
Content-Disposition: attachment 
Last-Modified: Sun, 18 Aug 2013 07:05:20 GMT 
ETag: "eacded76ceb4831aaeae2805c892fa1c" 
Content-Type: text/html 
Content-Length: 2585 
Server: AmazonS3 

此行是罪魁祸首:

Content-Disposition: attachment 

如果您使用AWS控制台,我相信可以通过选择S3中的文件并通过删除此属性修改其元数据来更改此控制台。

16

如果以编程方式执行此操作,则可以在上载中设置ContentType和/或ContentDisposition参数。

[PHP实例]

 $output = $s3->putObject(array(
      'Bucket' => $bucket, 
      'Key' => md5($share). '.html', 
      'ContentType' => 'text/html', 
      'Body' => $share, 
    )); 

putObject Docs

1

如果您正在使用Hashicorp Terraform你可以指定一个aws_s3_bucket_objectcontent-type如下

resource "aws_s3_bucket_object" "index" { 
    bucket = "yourbucketnamehere" 
    key = "index.html" 
    content = "<h1>Hello, world</h1>" 

    content_type = "text/html" 
} 

这应该适当地帮助您的内容在浏览器。