Host a static website
Serve a bucket's public objects as a static website at https://<bucket>.s3-website.<domain>, with an index and an error document.
Replace example-site with your bucket's name. The website serves only objects the bucket policy makes public.
Prerequisites
- Permission for
s3:PutBucketWebsiteon the bucket. - In the console, also
s3:GetBucketon the bucket to open it (without it the bucket's page says "Access denied"). - The bucket's objects are public (see Make objects public). Without
that, every page answers
403. - The bucket is not one the platform writes.
Step 1: Turn the website on
- Open Object Storage, open the bucket, then choose Website.
- Under Turn on, choose Serve the bucket’s files.
- For Index document, keep
index.htmlor enter another name. - (Optional) For Error document, enter
404.html. - Choose Turn on website.
The console says "Website on." and Status shows On, or On, not public with the banner "Every page answers 403: nothing in this bucket is public yet." while nothing in the bucket is public. Until the index or error document is uploaded, a banner says it is not in the bucket yet.
dcloud s3 bucket-access set-website example-site --index-document index.html --error-document 404.htmlPUT /s3/api/buckets/example-site/website
{ "indexDocument": "index.html", "errorDocument": "404.html" }resource "dcloud_bucket_website" "site" {
bucket = dcloud_bucket.site.id
index_document = "index.html"
error_document = "404.html"
}Over S3: aws --profile dcloud --endpoint-url https://s3.<domain> s3 website s3://example-site/ --index-document index.html --error-document 404.html.
Step 2: Upload the site
aws --profile dcloud --endpoint-url https://s3.<domain> s3 sync ./public s3://example-site/ --deleteThe AWS CLI sets each file's content type from its extension.
Result
The website answers at https://example-site.s3-website.<domain> (the console's Address). Its
certificate is issued on the first visit, in a few seconds.
| Request | Answer |
|---|---|
/, /docs/ |
index.html, docs/index.html |
/docs |
302 to /docs/ when docs/index.html exists and is public |
| a missing page | the error document with status 404 when it exists and is public; otherwise a plain 404 page |
| a private key | 403: only objects the bucket policy makes public are served |
| not GET or HEAD | 405 |
To send every request to another host instead, see Redirect website requests. For your own domain, see Use a custom domain for a website.
Turn the website off
Choose Turn off on the Website tab, run
dcloud s3 bucket-access delete-website example-site (s3:DeleteBucketWebsite), or
destroy the dcloud_bucket_website; custom domains are kept.
If it is refused
400naming the problem, such asAn index document is requiredorThe index document may not contain a slash.403This bucket is managed by the platform; its access cannot be changedfor a bucket the platform writes; the console saysA bucket the platform manages cannot be a website.403Forbiddenwithouts3:PutBucketWebsite; the console's controls are unavailable and sayNeeds s3:PutBucketWebsite on this bucket.(Turn off saysNeeds s3:DeleteBucketWebsite.)