Configure a bucket for static website hosting and set up mirroring-based back-to-origin routing rules. Once enabled, OSS serves static content directly from the bucket and redirects requests to the configured index and error pages.
Usage notes
The code examples in this topic use the region ID
cn-hangzhou, which corresponds to the China (Hangzhou) region. By default, a public endpoint is used. To access OSS from other Alibaba Cloud services within the same region, use an internal endpoint instead. For a full list of supported regions and endpoints, see Regions and endpoints.The examples read access credentials from environment variables. For setup instructions, see Configure access credentials.
-
The following Resource Access Management (RAM) permissions are required:
oss:PutBucketWebsite: required to configure static website hosting or mirroring-based back-to-origin.oss:GetBucketWebsite: required to query static website hosting or mirroring-based back-to-origin configurations.oss:DeleteBucketWebsite: required to delete static website hosting or mirroring-based back-to-origin configurations.
For instructions on granting these permissions, see Attach a policy to a RAM user.
Static website hosting
A static website serves fixed content—HTML pages, images, CSS, and client-side scripts—without server-side processing. All three operations (PutBucketWebsite, GetBucketWebsite, DeleteBucketWebsite) are covered in this section.
Configure
Query
Delete
Mirroring back-to-origin
Mirroring-based back-to-origin is designed for seamless data migration to OSS. If your service is running on a self-managed origin or another cloud service, you can migrate to OSS without any downtime. During the migration, OSS uses routing rules to fetch objects from the origin whenever a requested object has not yet been migrated—keeping your service running without gaps. All three operations (PutBucketWebsite, GetBucketWebsite, DeleteBucketWebsite) are covered in this section.
Configure
Query
Delete
References
For complete sample code for static website hosting and mirroring-based back-to-origin, see put_bucket_website.go, get_bucket_website.go, and delete_bucket_website.go.
For the API reference for configuring static website hosting or mirroring-based back-to-origin, see PutBucketWebsite.
For the API reference for querying these configurations, see GetBucketWebsite.
For the API reference for deleting these configurations, see DeleteBucketWebsite.