El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Configuring Static Website Hosting for a Bucket

Updated on 2024-03-05 GMT+08:00

Functions

OBS allows you to store static web page resources such as HTML web pages, flash files, videos, and audios in a bucket. When a client accesses these resources from the website endpoint of the bucket, the browser can directly resolve and present the resources to the client. This operation is applicable to:

  • Redirecting all requests to a website endpoint.
  • Adding routing rules that redirect specific requests.

You can perform this operation to create or update the website configuration of a bucket.

To perform this operation, you must have the PutBucketWebsite permission. By default, only the bucket owner can perform this operation. The bucket owner can grant the permission to other users by configuring the bucket policy or user policy.

NOTE:

Avoid using periods (.) in the destination bucket name. Otherwise, failures in client authentication certificate may occur when users use HTTPS for access.

The maximum size of a network configuration request for a bucket is 10 KB.

Request Syntax

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
PUT /?website HTTP/1.1 
Host: bucketname.obs.region.example.com
Content-Length: length
Date: date
Authorization: authorization
<WebsiteConfiguration> 
    <RedirectAllRequestsTo> 
        <HostName>hostName</HostName> 
    </RedirectAllRequestsTo> 
</WebsiteConfiguration>

Request Parameters

This request contains no parameters.

Request Headers

This request uses common headers. For details, see Table 3.

Request Elements

This request contains elements to specify the website configuration in XML format.

  • To redirect all website requests sent to the bucket's website endpoint, add the elements as described in Table 1.
    Table 1 Elements for redirecting all website requests

    Element

    Description

    Mandatory

    WebsiteConfiguration

    Root node configured on the website

    Type: container

    Parent: none

    Yes

    RedirectAllRequestsTo

    Describes the redirection behavior for every request to this bucket's website endpoint. If this element is present, no other siblings are allowed.

    Type: container

    Parent: WebsiteConfiguration

    Yes

    HostName

    Name of the host where requests will be redirected

    Type: string

    Parent: RedirectAllRequestsTo

    Yes

    Protocol

    The HTTP or HTTPS protocol used in redirecting requests. The default protocol is HTTP.

    Type: string

    Parent: RedirectAllRequestsTo

    No

  • To configure redirection rules, add the elements as described in Table 2.
    Table 2 Elements for adding rules that redirect requests

    Element

    Description

    Mandatory

    WebsiteConfiguration

    Root element for the website configuration

    Type: container

    Parent: none

    Yes

    IndexDocument

    Suff element

    Type: container

    Parent: WebsiteConfiguration

    Yes

    Suffix

    Suffix that is appended to a request initiated for a directory on the website endpoint. For example, if the suffix is index.html and you request for samplebucket/images/, the data that is returned will be for the object with the key name images/index.html in the samplebucket bucket. Suffix cannot be empty or contain slashes (/).

    Type: string

    Parent: IndexDocument

    Yes

    ErrorDocument

    Key element

    Type: container

    Parent: WebsiteConfiguration

    No

    Key

    Object key that is used when a 4XX error occurs. This element identifies the page that is returned when a 4XX error occurs.

    Type: string

    Parent: ErrorDocument

    Condition: Required when ErrorDocument is specified.

    No

    RoutingRules

    Routing element

    Type: container

    Parent: WebsiteConfiguration

    No

    RoutingRule

    Element of a redirection rule. A redirection rule contains a Condition and a Redirect. When the Condition is matched, Redirect takes effect.

    Type: container

    Parent: RoutingRules

    At least the RoutingRule element is required.

    Yes

    Condition

    Element for describing a condition that must be met for the specified redirection to apply.

    Type: container

    Parent: RoutingRule

    No

    KeyPrefixEquals

    Object key name prefix when the redirection is applied.

    Example:

    • To redirect the request for object ExamplePage.html, the KeyPrefixEquals is set to ExamplePage.html.

    Type: string

    Parent: Condition

    Condition: Required when the ancestor element Condition is specified and sibling HttpErrorCodeReturnedEquals is not specified. If two conditions are specified, both conditions must be true for the Redirect to be applied.

    No

    HttpErrorCodeReturnedEquals

    HTTP error code returned after the Redirect has taken effect. The specified Redirect is applied only when the error code returned equals this value.

    Example:

    • If you want to redirect requests to NotFound.html when HTTP error code 404 is returned, set HttpErrorCodeReturnedEquals to 404 in Condition, and set ReplaceKeyWith to NotFound.html in Redirect.

    Type: string

    Parent: Condition

    Condition: Required when ancestor element Condition is specified and sibling KeyPrefixEquals is not specified. If multiple conditions are specified, the Redirect takes effect only after all conditions are met.

    No

    Redirect

    Element for redirection information. You can redirect requests to another host, to another web page, or with another protocol. You can specify an error code to be returned after an error.

    Type: container

    Parent: RoutingRule

    Yes

    Protocol

    Protocol used in the redirection request

    Type: string

    Parent: Redirect

    Value options: http, https

    Condition: Not required if one of the siblings is present.

    No

    HostName

    Host name used in the redirection request.

    Type: string

    Parent: Redirect

    Condition: Not required if one of the siblings is present.

    No

    ReplaceKeyPrefixWith

    The object name prefix used in the redirection request. OBS replaces the value of KeyPrefixEquals with the value you specified here for ReplaceKeyPrefixWith.

    Example:

    To redirect all requests for docs (objects in the docs directory) to documents (objects in the documents directory), set KeyPrefixEquals to docs under Condition and ReplaceKeyPrefixWith to documents under Redirect. This way, requests for object docs/a.html will be redirected to documents/a.html.

    Type: string

    Parent: Redirect

    Condition: Not required if one of the siblings is present. Can be present only if ReplaceKeyWith is not provided.

    No

    ReplaceKeyWith

    The object name used in the redirection request. OBS replaces the entire object name in the request with the value you specified here for ReplaceKeyWith.

    Example:

    To redirect requests for all objects in the docs directory to documents/error.html, set KeyPrefixEquals to docs under Condition and ReplaceKeyWith to documents/error.html under Redirect. This way, requests for both objects docs/a.html and docs/b.html will be redirected to documents/error.html.

    Type: string

    Parent: Redirect

    Condition: Not required if one of the siblings is present. Can be present only if ReplaceKeyPrefixWith is not provided.

    No

    HttpRedirectCode

    HTTP status code returned after the redirection request

    Type: string

    Parent: Redirect

    Condition: Not required if one of the siblings is present.

    No

Response Syntax

1
2
3
HTTP/1.1 status_code
Date: date
Content-Length: length

Response Headers

The response to the request uses common headers. For details, see Table 1.

Response Elements

This response contains no elements.

Error Responses

No special error responses are returned. For details about error responses, see Table 2.

Sample Request: Redirecting All Requests for a Bucket to Another Bucket or URL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
PUT /?website HTTP/1.1
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.example.com
Accept: */*
Date: WED, 01 Jul 2015 03:40:29 GMT
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:pUK7Yp0yebnq4P6gqzVjoS7whoM=
Content-Length: 194

<WebsiteConfiguration xmlns="http://obs.example.com/doc/2015-06-30/">
  <RedirectAllRequestsTo>
    <HostName>www.example.com</HostName>
  </RedirectAllRequestsTo>
</WebsiteConfiguration>

Sample Response: Redirecting All Requests for a Bucket to Another Bucket or URL

1
2
3
4
5
6
HTTP/1.1 200 OK
Server: OBS
x-obs-request-id: BF2600000164360D144670B9D02AABC6
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSItqMZ/AoFUX97l1xx8s67V3cCQtXWk
Date: WED, 01 Jul 2015 03:40:29 GMT
Content-Length: 0

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback