• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. User Guide (S3cmd)
  4. Operation Guide
  5. Bucket Management
  6. Configuring Static Website Hosting

Configuring Static Website Hosting

Bucket owners or users who have the following permissions on the buckets can configure static website hosting for the buckets and access the static websites using the bucket domain names.

  • s3:PutBucketWebsite
  • s3:GetBucketWebsite
  • s3:DeleteBucketWebsite
NOTE:

You can obtain these permissions by configuring a bucket policy. For details about how to configure a bucket policy, see section Configuring a Bucket Policy.

Prerequisites

The web page files required by the static website have been uploaded to the specified bucket. For details about how to upload objects, see section Uploading an Object.
NOTE:

Your static website files must contain one default home page file and can contain one default 404 page. When a client attempts to access the static website using the bucket domain name, the browser can resolve the default website resources and present them to the end users.

Procedure

  1. Open the command line tool.
  2. Run the following command to configure static website hosting for a bucket:

    s3cmd ws-create --ws-index=website_index --ws-error=website_error s3://my-bucket

    NOTE:
    • --ws-index=website_index is the website's default home page and website_index varies with the actual home page file name. Only files in the current bucket can be used as the index page (home page) of the static website. If related file names are not entered, the default home page settings are not enabled. OBS only allows files such as index.html in the root directory of a bucket to function as the default homepage. That is to say, do not set the default homepage with a multi-level directory structure (for example, /page/index.html).
    • --ws-error=website_error is the parameter used to set the website's default 404 page and website_error varies with the actual file name of the 404 error page. Only files in the current bucket can be used as the default 404 (Not Found) page of the static website. This error page is returned when incorrect path is being accessed. If this parameter is not used, the default 404 page settings are not enabled.
    • my-bucket is the bucket for which static website hosting is to be configured.

    If the following information is displayed in the command output, it indicates that the static website is successfully set:

    Bucket 's3://my-bucket/': website configuration created.

  3. (Optional) Run the following command to obtain related information, such as the domain name used to access the bucket website:

    s3cmd ws-info s3://my-bucket

    Check whether the following information is displayed in the command output:

    Bucket s3://my-bucket/: Website configuration
    Website endpoint: http://my-bucket.example.com/
    Index document:   index.html
    Error document:   error.html

  4. (Optional) Open the browser and enter information in the address bar in the following format:

    http:// Bucket name . Domain name used to access the hosted static website on OBS
    NOTE:

    Configuration of static website hosting will take effect within 2 minutes. If you fail to access the static website, try again later.

Follow-up Procedure

You can disable static website hosting for a bucket as follows if necessary:

  1. Open the command line tool.
  2. Run the following command to delete the static website hosting configuration of a bucket as follows:

    s3cmd ws-delete s3://my-bucket

    If the following information is displayed in the command output, it indicates that the static website hosting configuration is successfully deleted:

    Bucket 's3://my-bucket/': website configuration deleted.

  3. (Optional) Run the following command to view the static website information:

    s3cmd ws-info s3://my-bucket

    If the following information is displayed in the command output, it indicates that static website hosting is not configured for the bucket:

    Bucket s3://my-bucket/: Unable to receive website configuration.