Why doesn’t Amazon S3 automatically serve /foo/index.html when I ask for /foo or /foo/?
I am looking into serving my static site with Amazon S3. I have created a bucket and uploaded my files; under the “Website” tab in the AWS Management Console I have checked “Enabled” and entered index.html
in the “Index Document” field. I have the following bucket policy:
{
"Version": "2008-10-17",
"Id": "924a2348-de0e-43aa-bb06-83adbcd1db22",
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Acti开发者_Go百科on": "s3:GetObject",
"Resource": "arn:aws:s3:::my-bucket/*"
}
]
}
where I have my bucket’s name instead of my-bucket
. Under the “Permissions” tab I have also granted “Everyone” the list ability.
If I try to access my-bucket.s3.amazonaws.com/index.html
my page (and its images, CSS, etc.) shows up as expected. However, just going to my-bucket.s3.amazonaws.com
or my-bucket.s3.amazonaws.com/
gives a directory-listing XML file instead of showing the page. If I try to go to my-bucket.s3.amazonaws.com/subdirectory
I get an error (in XML) saying “The specified key does not exist.” Most bizarrely, if I try to go to my-bucket.s3.amazonaws.com/subdirectory/
(with a trailing slash), no page loads but my browser downloads an empty file named download
. (Once again, going to my-bucket.s3.amazonaws.com/subdirectory/index.html
shows the page as expected.)
Am I doing something wrong here? How do I get S3 to show the index.html
file when a directory name is requested?
Looks like you need to configure a root (index) document:
http://docs.amazonwebservices.com/AmazonS3/latest/dev/IndexDocumentSupport.html
http://aws.typepad.com/aws/2011/02/host-your-static-website-on-amazon-s3.html
精彩评论