此操作用来配置网站托管属性。如果Bucket已经存在了website,此操作会替换原有website。只有根用户和拥有PUT Bucket WebSite权限的子用户才能执行此操作。
注意
如果配置静态网站托管后,当匿名用户直接访问Bucket的域名,会将静态网站文件下载到本地。如果要实现访问静态网站时是预览网站内容,而非下载静态网站文件,静态网站域名须是Bucket绑定的已备案自定义域名,为Bucket绑定自定义域名请联系天翼云客服申请。
OOS自有网站托管域名不支持HTTPS访问,用户自定义域名支持HTTPS访问。如果需要支持通过HTTPS访问,请联系天翼云客服,提供域名证书,证书支持格式:crt+key或者PEM,请确保提供的证书在有效期内,建议证书有效期至少1年及以上,避免使用免费证书。
设置Bucket的网络配置请求消息体的上限是10KiB。
尽量避免目标Bucket名中带有“.”,否则通过HTTPS访问时可能出现客户端校验证书出错。
网站托管配置步骤如下:
-
创建一个公共读属性的存储桶(Bucket)。
-
向天翼云客服提交工单,申请客户自定义域名添加白名单。
-
在域名管理中添加别名。
- 如果不使用CDN加速,将Bucket的CNAME Record Value(bucketname.oos-website-cn.oos-xx.ctyunapi.cn)作为别名添加到域名管理系统中。
- 如果使用CDN加速,将CDN厂商提供的别名添加到域名管理系统中,然后在CDN回源地址中配置OOS侧的CNAME Record Value,并将回源host配置为您的自定义域名(如yourdomain.com)。
说明创建Bucket时显示的Endpoint为oos-cn.ctyunapi.cn,该Endpoint是针对整个对象存储网络的域名,该域名在解析时,会根据用户地理位置的不同解析到不同的资源池地址。如果创建Bucket时有多个数据位置,系统默认选取创建时第一个有效数据位置作为CNAME Record Value(bucketname.oos-website-cn.oos-xx.ctyunapi.cn)。CNAME Record Value可以通过控制台Bucket属性中的网站查看。如果创建Bucket时,只有一个数据位置可用,则在Bucket区域中展示的CNAME Record Value为bucketname.oos-website-cn.oos-cn.ctyunapi.cn。所以如果使用静态网站托管,建议您根据Bucket区域属性中的数据位置,选择您想使用的数据位置的CNAME Record Value作为域名管理系统中的别名。例如您创建Bucket时有效数据位置为沈阳、兰州、成都、贵阳,则Bucket中展示的CNAME Record Value为bucketname.oos-website-cn.oos-lnsy.ctyunapi.cn,您可以将bucketname.oos-website-cn.oos-lnsy.ctyunapi.cn作为别名,也可以将兰州、成都或者贵阳为域名的CNAME Record Value作为您的别名。
-
上传文件。
将网站的所有文件(html、CSS、js、图片等)上传到之前创建的Bucket中, 注意要保持文件之间的相对路径。
-
配置Bucket网站属性:可以通过控制台或者调用本接口配置。
请求语法
托管模式为当前容器
PUT /?website HTTP/1.1
Host: BucketName.oos-cn.ctyunapi.cn
Date: date
Content-Length: ContentLength
Authorization: signatureValue
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>errorDocument.html</Key>
</ErrorDocument>
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>string</HttpErrorCodeReturnedEquals>
<KeyPrefixEquals>string</KeyPrefixEquals>
</Condition>
<Redirect>
<HostName>string</HostName>
<Protocol>string</Protocol>
<ReplaceKeyPrefixWith>string</ReplaceKeyPrefixWith>
<ReplaceKeyWith>string</ReplaceKeyWith>
</Redirect>
</RoutingRule>
</RoutingRules>
</WebsiteConfiguration>
托管模式为重定向请求
PUT /?website HTTP/1.1
Host: BucketName.oos-cn.ctyunapi.cn
Date: date
Content-Length: ContentLength
Authorization: signatureValue
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<RedirectAllRequestsTo>
<HostName>string</HostName>
<Protocol>string</Protocol>
</RedirectAllRequestsTo>
</WebsiteConfiguration>
请求参数
名称 | 描述 | 是否必须 |
---|---|---|
WebsiteConfiguration | 请求的容器。 类型:容器。 子节点:IndexDocument、ErrorDocument、RoutingRules或RedirectAllRequestsTo。 注意:IndexDocument和RedirectAllRequestsTo互斥。如果填写了RedirectAllRequestsTo,则IndexDocument、ErrorDocument、RoutingRules都不能填写。 |
是 |
IndexDocument | Suffix元素的容器。 注意 :如果未填写RedirectAllRequestsTo,则IndexDocument必填。 类型:容器。 父节点:WebsiteConfiguration。 子节点:Suffix。 |
否 |
Suffix | 在请求website endpoint 上的路径时,Suffix会被加在请求的后面。例如,如果suffix是Index.html,而你请求的是bucket/images/,那么返回的响应是名为images/index.html的Object。 类型:字符串。 父节点:IndexDocument。 |
是 |
ErrorDocument | Key的容器。 类型:容器。 父节点:WebsiteConfiguration。 子节点:Key。 |
否 |
Key | 如果出现4XX错误,会返回指定的Object。 类型:字符串。 有效值:长度为1~1024的字符串。 父节点:ErrorDocument。 |
是 |
RoutingRules | 托管模式配置到当前容器的重定向规则容器。 注意:如果RoutingRules下有多个RoutingRule,各RoutingRule之间无影响,按照配置的先后顺序向下执行,当有一个满足条件时,就不再继续向后匹配。如果都没有匹配,就不使用重定向规则。 类型:容器。 父节点:WebsiteConfiguration。 子节点:RoutingRule。 |
否 |
RoutingRule | 重定向规则的容器。一条重定向规则包含一个Condition和一个Redirect,当Condition匹配时,Redirect生效。容器中至少要有一个重定向规则。 注意 :一个RoutingRule下,出现多个Condition和Redirect时,以最后一个为准。 类型:容器。 父节点:RoutingRules。 子节点:Condition、Redirect。 |
是 |
Condition | 描述重定向规则匹配的条件的容器。如果重定向规则匹配的条件未配置,则重定向规则将应用于所有请求。 注意:该容器可以不配置,如果配置,则至少应该包含HttpErrorCodeReturnedEquals、KeyPrefixEquals中的一个。 类型:容器。 父节点:RoutingRule。 子节点:HttpErrorCodeReturnedEquals、KeyPrefixEquals。 |
否 |
HttpErrorCodeReturnedEquals | 指定Redirect生效时的HTTP错误码。当发生错误时,如果错误码等于这个值,那么Redirect生效。 注意:HttpErrorCodeReturnedEquals和KeyPrefixEquals同时存在时,只有都匹配时,Redirect才生效。 类型:字符串。 取值:[ 400, 417 ],[ 500, 505]。 例如:当返回的http错误码为404时重定向到NotFound.html,可以将Condition中的HttpErrorCodeReturnedEquals设置为404,Redirect中的ReplaceKeyWith设置为NotFound.html。 父节点:Condition。 |
否 |
KeyPrefixEquals | 重定向规则生效时的文件名的前缀。 注意 :HttpErrorCodeReturnedEquals 和KeyPrefixEquals同时存在时,只有都匹配时,Redirect才生效。 类型:字符串。 取值:长度为0-1024的字符串。 父节点:Condition。 |
否 |
Redirect | 重定信息容器。 注意 :Redirect配置包含的元素可以为空,也可以包含以下元素:Protocol、HostName、ReplaceKeyPrefixWith、ReplaceKeyWith。当某一元素存在多条值时以最后一条为准。 类型:容器。 父节点:RoutingRule。 子节点:Protocol、HostName、ReplaceKeyPrefixWith、ReplaceKeyWith。 |
是 |
Protocol | 重定向请求时使用的协议。 类型:字符串。 取值:http、https,默认值为http。 父节点:Redirect或者RedirectAllRequestsTo。 |
否 |
HostName | 重定向请求时使用的站点名。 如果父节点为RedirectAllRequestsTo,此项必须填写。 类型:字符串。 取值:1~1024个字符,不能包含空格。父节点为Redirect,也不能包含斜杠(/)。 父节点:Redirect或者RedirectAllRequestsTo。 |
否 |
ReplaceKeyPrefixWith | 重定向请求时使用的文件名前缀。 注意:ReplaceKeyPrefixWith与ReplaceKeyWith不能同时存在。 类型:字符串。 取值:0~1024个字符。 父节点:Redirect。 |
否 |
ReplaceKeyWith | 指定重定向请求时使用的文件名。 注意:ReplaceKeyPrefixWith与ReplaceKeyWith不能同时存在。 类型:字符串。 取值:0~1024个字符。 父节点:Redirect。 |
否 |
RedirectAllRequestsTo | 托管模式为重定向请求的容器。 注意 :如果未填写IndexDocument,则RedirectAllRequestsTo必填。如果填写了RedirectAllRequestsTo,则IndexDocument、ErrorDocument、RoutingRules都不能填写。 父节点:WebsiteConfiguration。 子节点:HostName、Protocol。 |
否 |
请求示例1
指定index.html为首页,error.html为错误页。
PUT /?website HTTP/1.1
x-amz-content-sha256: UNSIGNED-PAYLOAD
Authorization: AWS4-HMAC-SHA256 Credential=userak2222222222368/20220718/cd/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=0db87d431516bcb20e72b4a8989af21ded5bbdafcbf358ee4bb41ff7685a2a11
x-amz-date: 20220718T084033Z
Host: example.oos-cn.ctyunapi.cn
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 268
<WebsiteConfiguration xmlns='http://s3.amazonaws.com/doc/2006-03-01/'>
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>error.html</Key>
</ErrorDocument>
</WebsiteConfiguration>
响应示例1
HTTP/1.1 200 OK
Date: Mon, 18 Jul 2022 08:40:33 GMT
x-amz-request-id: 91dd8b753eba4237aefaf102080508e70a14f6f8fbf6ff0bec
Content-Length: 0
Server: CTYUN
请求示例2
将所有的请求重定向到主机example.com,且使用https协议。
PUT /?website HTTP/1.1
x-amz-content-sha256: UNSIGNED-PAYLOAD
Authorization: AWS4-HMAC-SHA256 Credential=userak2222222222222/20220718/cd/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=7965b41510153bb913d64bcaf00aa8c4200d1ea52e0973fbd6cad70ffb0011c9
x-amz-date: 20220718T084539Z
Host: www.example.com.oos-cn.ctyunapi.cn
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 252
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<RedirectAllRequestsTo>
<HostName>example.com</HostName>
<Protocol>https</Protocol>
</RedirectAllRequestsTo>
</WebsiteConfiguration>
响应示例2
HTTP/1.1 200 OK
Date: Mon, 18 Jul 2022 08:45:39 GMT
x-amz-request-id: 98449be04a8e4abb93dfd6e7edeaedcceff9dbdde0dbe4f0d1
Content-Length: 0
Server: CTYUN
请求示例3
指定index.html为首页,error.html为错误页。将所有前缀为“docs”的请求,全部重定向至本Bucket中前缀为“documents/”的文件上。
PUT /?website HTTP/1.1
x-amz-content-sha256: UNSIGNED-PAYLOAD
Authorization: AWS4-HMAC-SHA256 Credential=userak2222222222345/20220718/cd/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=60972542afaad9aa0c7afba0658be3a0e367e4d66be6158aed03956521d91bc2
x-amz-date: 20220718T085146Z
Host: www.example.com.oos-cn.ctyunapi.cn
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 471
<WebsiteConfiguration xmlns='http://s3.amazonaws.com/doc/2006-03-01/'>
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>error.html</Key>
</ErrorDocument>
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>docs</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>documents/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
</WebsiteConfiguration>
响应示例3
HTTP/1.1 200 OK
Date: Mon, 18 Jul 2022 08:51:46 GMT
x-amz-request-id: 01413e0eca2e4cbf66b2a9bac0bdc09fc2ccaeb0b3aeb7c3a4
Content-Length: 0
Server: CTYUN
请求示例4
指定index.html为首页,error.html为错误页。如果发生404错误,重定向到主机“www.example.com”上前缀为“report-404/”的文件。
PUT /?website HTTP/1.1
x-amz-content-sha256: UNSIGNED-PAYLOAD
Authorization: AWS4-HMAC-SHA256 Credential=userak2222222222222/20220718/cd/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=36b2f54e31104e14881eb0d95fd67c54cb2b46b007705bd9488d6645aacb5df2
x-amz-date: 20220718T090739Z
User-Agent: Java/1.8.0_221
Host: www.example.com.oos-cn.ctyunapi.cn
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 538
<WebsiteConfiguration xmlns='http://s3.amazonaws.com/doc/2006-03-01/'>
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>error.html</Key>
</ErrorDocument>
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>www.example.com</HostName>
<ReplaceKeyPrefixWith>report-404/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
</WebsiteConfiguration>
响应示例4
HTTP/1.1 200 OK
Date: Mon, 18 Jul 2022 09:07:39 GMT
x-amz-request-id: 2814d402a9f64041024e45565c595c3b5e684a4c4f4a535f40
Content-Length: 0
Server: CTYUN
请求示例5
指定index.html为首页,error.html为错误页。将前缀为“images/”的请求,重定向至本Bucket内的“errorpage.html”文件。
PUT /?website HTTP/1.1
x-amz-content-sha256: UNSIGNED-PAYLOAD
Authorization: AWS4-HMAC-SHA256 Credential=userak2222222227856/20220718/cd/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=6d6a75c2c8564a13601b8b5e51d3ad1ebe3d4f1a8c3341d2c4c1794a57b04aa9
x-amz-date: 20220718T091138Z
Host: test-bucket.oos-cn.ctyunapi.cn
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 465
<WebsiteConfiguration xmlns='http://s3.amazonaws.com/doc/2006-03-01/'>
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>error.html</Key>
</ErrorDocument>
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>images/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyWith>errorpage.html</ReplaceKeyWith>
</Redirect>
</RoutingRule>
</RoutingRules>
</WebsiteConfiguration>
响应示例5
HTTP/1.1 200 OK
Date: Mon, 18 Jul 2022 09:11:38 GMT
x-amz-request-id: 2ef16ade344d4c111f6b6273797679587b8567696c67707c5d
Content-Length: 0
Server: CTYUN