- Newest
- Most votes
- Most comments
It's not the bucket settings or file type, they all look good. You can prove this by viewing the index.html file locally in a browser and it will look exactly the same as the version that's being served from the S3 bucket.
The problem is the content of the index.html file itself.
$ curl http://hduaneblack.com.s3-website.us-east-2.amazonaws.com/index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="2685.2">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
</style>
</head>
<body>
<p class="p1"><!DOCTYPE html></p>
<p class="p1"><html></p>
<p class="p1"><span class="Apple-converted-space"> </span><head></p>
<p class="p1"><span class="Apple-converted-space"> </span><title>H. Duane Black</title></p>
<p class="p1"><span class="Apple-converted-space"> </span></head></p>
<p class="p1"><span class="Apple-converted-space"> </span><body></p>
<p class="p1"><span class="Apple-converted-space"> </span><h1>Welcome to my AWS site</h1></p>
<p class="p1"><span class="Apple-converted-space"> </span><p>This is a private test site while I build my author website.</p></p>
<p class="p1"><span class="Apple-converted-space"> </span></body></p>
<p class="p1"></html></p>
</body>
</html>
The rows between <body> and </body> are basically telling the browser to display the text that follows to look like rows of raw HTML, and not to be like what that HTML would look would look like when rendered (if that makes sense).
Simplify the index.html to look like:
<!DOCTYPE html>
<html>
<head>
<title>H. Duane Black</title>
</head>
<body>
<h1>Welcome to my AWS site</h1>
<p>This is a private test site while I build my author website.</p>
</body>
</html>
Then upload that to the bucket, set the permissions & filetype etc., and view it in a browser now.
This issue with HTML files being served as text/plain despite having the correct Content-Type metadata is a common problem with S3 static website hosting. Here are some potential causes and solutions:
-
Website Endpoint vs. S3 Object URL: Make sure you're accessing your website through the S3 website endpoint (http://hduaneblack.com.s3-website.us-east-2.amazonaws.com) and not the regular S3 object URL. The regular S3 object URL might ignore the Content-Type metadata.
-
Bucket Policy Configuration: While you mentioned your bucket policy allows public read access, ensure it specifically includes the
s3:GetObjectpermission for all objects in your bucket. Your policy should look similar to:
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::hduaneblack.com/*"]
}]
}
-
Block Public Access Settings: Check that "Block all public access" is turned off at the bucket level, as this could override your bucket policy.
-
Content-Type Setting Method: When uploading files, try explicitly setting the Content-Type using the AWS CLI instead of the console:
aws s3 cp index.html s3://hduaneblack.com/ --content-type "text/html"
-
File Permissions: Ensure the files have the correct permissions set to be publicly readable.
-
CloudFront Configuration: If you're using CloudFront, check that it's not overriding your Content-Type settings.
-
Try AWS Amplify Hosting: If you continue to face issues, consider using AWS Amplify Hosting, which can simplify the process of hosting static websites and handle many of these configuration details automatically.
If you've verified all these points and are still experiencing issues, you might want to try creating a new bucket with a different name to see if the problem persists, which could help identify if there's a specific issue with your current bucket configuration.
Sources
Rendering problem of the static website hosting | AWS re:Post
Use Amazon S3 website hosting to host without a single web server - Hosting Static Websites on AWS
Relevant content
asked 3 years ago
asked 2 years ago
asked 2 years ago
