Static hosting, CORS and cache-control¶
Static hosting¶
Static hosting turns the custom domain into a website: a request for a
directory (/, /docs/) is rewritten to the index document (/docs/index.html). That is
the whole feature.
| Setting | Value |
|---|---|
enabled |
on or off; the custom domain is only deployed while it is on |
index_document |
required, default index.html, appended to every path ending in / |
error_document |
stored but not applied; a missing object returns the RGW 404 |
Objects have to be readable for anonymous visitors: set the bucket policy preset to
public-read (Geofencing and policies). Static hosting does not add
CORS headers; CORS comes from the bucket's CORS configuration below.
CORS¶
CORS is a configuration of the bucket in RGW. Rules set in the portal are written to the
bucket with PutBucketCORS and apply to every way of reaching the bucket, S3 endpoint and
custom domain alike. aws s3api get-bucket-cors shows them.
| Field | Rule |
|---|---|
allowed_origins |
required; * or http(s)://host[:port], * allowed inside the host |
allowed_methods |
required; any of GET, HEAD, PUT, POST, DELETE |
allowed_headers |
required; * or headers from the list below |
expose_headers |
optional; from the list below |
max_age_seconds |
required; 0 to 86400 |
| rules per bucket | at most 10 |
Allowed request headers: Authorization, Content-Type, Content-MD5,
Content-Disposition, Content-Encoding, Content-Length, Cache-Control, Accept,
Origin, Range, If-Match, If-None-Match, If-Modified-Since, x-amz-content-sha256,
x-amz-date, x-amz-security-token, x-amz-meta-*, x-amz-server-side-encryption,
x-amz-acl, x-amz-storage-class.
Exposable response headers: ETag, Content-Range, Content-Disposition,
Content-Encoding, x-amz-request-id, x-amz-id-2, x-amz-server-side-encryption,
x-amz-version-id, x-amz-delete-marker, x-amz-storage-class, x-amz-expiration,
x-amz-restore, x-amz-mp-parts-count.
Set CORS either in the portal or with the S3 API, not both: the portal writes its stored
rules to the bucket on every change and does not read back changes made with
put-bucket-cors.
Cache-Control¶
Applies to responses served through the custom domain only; the S3 endpoint returns the object's own headers.
| Setting | Value |
|---|---|
max_age |
required, 0 to 31536000 seconds |
mode |
fallback (default): header is added only when the object has no Cache-Control; overwrite: header replaces it |
directives |
optional, from public, private, no-cache, no-store, no-transform, must-revalidate, proxy-revalidate, immutable |
The header sent is the directives followed by max-age=<max_age>, for example
public, immutable, max-age=31536000. Per-object Cache-Control set at upload time wins
in fallback mode.