forked from docs/doc-exports
Reviewed-by: Sabelnikov, Dmitriy <dmitriy.sabelnikov@t-systems.com> Co-authored-by: zhangyue <zhangyue164@huawei.com> Co-committed-by: zhangyue <zhangyue164@huawei.com>
140 lines
20 KiB
HTML
140 lines
20 KiB
HTML
<a name="en-us_topic_0045853755"></a><a name="en-us_topic_0045853755"></a>
|
|
|
|
<h1 class="topictitle1">Configuring Static Website Hosting</h1>
|
|
<div id="body1499758606807"><p id="en-us_topic_0045853755__p30121176153913">You can configure static website hosting for a bucket and then use the bucket's domain name to access static websites hosted in the bucket.</p>
|
|
<p id="en-us_topic_0045853755__p885135018528">It can take up to two minutes for the configuration of static website hosting to take effect.</p>
|
|
<div class="section" id="en-us_topic_0045853755__section11221613153921"><h4 class="sectiontitle">Prerequisites</h4><p id="en-us_topic_0045853755__p1146611514350">Web page files required for static website hosting have been uploaded to the specified bucket.</p>
|
|
<p id="en-us_topic_0045853755__p1812645682117">The static website files hosted in the bucket are accessible to anonymous users.</p>
|
|
<p id="en-us_topic_0045853755__p3350182614313">Static web page files in the Cold storage class have been restored. For more information, see <a href="obs_03_0320.html">Restoring an Object from Cold Storage</a>.</p>
|
|
</div>
|
|
<div class="section" id="en-us_topic_0045853755__section11587693153957"><h4 class="sectiontitle">Procedure</h4><ol id="en-us_topic_0045853755__ol44271394154014"><li id="en-us_topic_0045853755__li99821455306"><span>In the bucket list, click the bucket you want to operate. The <strong id="en-us_topic_0045853755__obs_03_0307_b144421021120">Overview</strong> page is displayed.</span></li><li id="en-us_topic_0045853755__li45818654181751"><span>(<strong id="en-us_topic_0045853755__b7869135132012">Optional</strong>) If the static website files in the bucket are not accessible to anonymous users, perform this step. If they are already accessible to everyone, skip this step.</span><p><p id="en-us_topic_0045853755__p18712161416268">Grant the read permission for static website files to anonymous users. For details, see <a href="obs_03_0132.html">Granting Anonymous Users Permission to Access Objects</a>.</p>
|
|
<p id="en-us_topic_0045853755__p14415184985410">If the bucket contains only static website files, configure the <strong id="en-us_topic_0045853755__b1273611558518">Public Read</strong> policy for the bucket so that all files in it are publicly accessible.</p>
|
|
<ol type="a" id="en-us_topic_0045853755__ol56026477144312"><li id="en-us_topic_0045853755__li26219314144346">Choose <strong id="en-us_topic_0045853755__b1966141115407">Permissions</strong> > <strong id="en-us_topic_0045853755__b7671191919400">Bucket Policies</strong>.</li><li id="en-us_topic_0045853755__li820711719166">In the <strong id="en-us_topic_0045853755__b137091459121110">Standard Bucket Policies</strong> area, select the <strong id="en-us_topic_0045853755__b8285215161211">Public Read</strong> policy for the bucket.</li><li id="en-us_topic_0045853755__li588503161565">Click <strong id="en-us_topic_0045853755__b9882162941218">Public Read</strong>. For details, see <a href="#en-us_topic_0045853755__fig15186794193556">Figure 1</a>. In the confirmation dialog box that is displayed, click <strong id="en-us_topic_0045853755__b1842219132">Yes</strong>.<div class="fignone" id="en-us_topic_0045853755__fig15186794193556"><a name="en-us_topic_0045853755__fig15186794193556"></a><a name="fig15186794193556"></a><span class="figcap"><b>Figure 1 </b>Configuring the public read permission</span><br><span><img id="en-us_topic_0045853755__image1956565091517" src="en-us_image_0129612765.png" title="Click to enlarge" class="imgResize"></span></div>
|
|
</li></ol>
|
|
</p></li><li id="en-us_topic_0045853755__li18830181855820"><span>In the <strong id="en-us_topic_0045853755__b838813813356">Basic Configurations</strong> area, click <strong id="en-us_topic_0045853755__b14321164593516">Static Website Hosting</strong>. The <strong id="en-us_topic_0045853755__b1936125173510">Static Website Hosting</strong> page is displayed.</span><p><p id="en-us_topic_0045853755__p1732877134316">Alternatively, you can choose <strong id="en-us_topic_0045853755__b16921115721615">Basic Configurations</strong> > <strong id="en-us_topic_0045853755__b8474115171713">Static Website Hosting</strong> from the navigation pane on the left.</p>
|
|
</p></li><li id="en-us_topic_0045853755__li16425445133613"><span>Click <strong id="en-us_topic_0045853755__b145689166565">Configure Static Website Hosting</strong>. The <strong id="en-us_topic_0045853755__b16569201612565">Configure Static Website Hosting</strong> dialog box is displayed.</span></li><li id="en-us_topic_0045853755__li16729105453"><span>Enable <strong id="en-us_topic_0045853755__b6575121121913">Status</strong>.</span></li><li id="en-us_topic_0045853755__li13201511640"><span>Set the hosting type to the current bucket. For details, see <a href="#en-us_topic_0045853755__fig1131112528711">Figure 2</a>.</span><p><div class="fignone" id="en-us_topic_0045853755__fig1131112528711"><a name="en-us_topic_0045853755__fig1131112528711"></a><a name="fig1131112528711"></a><span class="figcap"><b>Figure 2 </b>Configuring static website hosting</span><br><span><img id="en-us_topic_0045853755__image27411688519" src="en-us_image_0145846197.png" title="Click to enlarge" class="imgResize"></span></div>
|
|
<p id="en-us_topic_0045853755__p261473213246"></p>
|
|
</p></li><li id="en-us_topic_0045853755__li65471095155127"><span>Configure the homepage and 404 error page.</span><p>
|
|
<ul id="en-us_topic_0045853755__ul58086424"><li id="en-us_topic_0045853755__li44406302"><strong id="en-us_topic_0045853755__b1133390286">Home Page</strong>: specifies the default homepage of the static website. When OBS Console is used to configure static website hosting, only HTML web pages are supported. When APIs are used to configure static website hosting, OBS does not have such a restriction, but the object <strong id="en-us_topic_0045853755__b95712271369">Content-Type</strong> must be specified.<p id="en-us_topic_0045853755__p64112402">OBS only allows files such as <strong id="en-us_topic_0045853755__b7877104162117">index.html</strong> in the root directory of a bucket to function as the default homepage. Do not set the default homepage with a multi-level directory structure (for example, <strong id="en-us_topic_0045853755__b887715452112">/page/index.html</strong>).</p>
|
|
</li><li id="en-us_topic_0045853755__li40140706"><strong id="en-us_topic_0045853755__b1074981173714">404 Error Page</strong>: specifies the error page returned when an error occurs during static website access. When OBS Console is used to configure static website hosting, only HTML, JPG, PNG, BMP, and WebP files under the root directory are supported. When APIs are used to configure static website hosting, OBS does not have such a restriction, but the object <strong id="en-us_topic_0045853755__b12328101310377">Content-Type</strong> must be specified.</li></ul>
|
|
</p></li><li id="en-us_topic_0045853755__li53951195155255"><span><strong id="en-us_topic_0045853755__b67601913142610">Optional</strong>: In <strong id="en-us_topic_0045853755__b1499976005142610">Redirection Rules</strong>, configure redirection rules. Requests that comply with the redirection rules are redirected to the specific host or page.</span><p><p id="en-us_topic_0045853755__p2518484920120">A redirection rule is compiled in the JSON or XML format. Each rule contains a <strong id="en-us_topic_0045853755__b261716153396">Condition</strong> and a <strong id="en-us_topic_0045853755__b16476172503913">Redirect</strong>. The parameters are described in <a href="#en-us_topic_0045853755__table59166151447">Table 1</a>.</p>
|
|
|
|
<div class="tablenoborder"><a name="en-us_topic_0045853755__table59166151447"></a><a name="table59166151447"></a><table cellpadding="4" cellspacing="0" summary="" id="en-us_topic_0045853755__table59166151447" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameter description</caption><thead align="left"><tr id="en-us_topic_0045853755__row2916201574415"><th align="left" class="cellrowborder" valign="top" width="20%" id="mcps1.3.4.2.8.2.2.2.4.1.1"><p id="en-us_topic_0045853755__p1091631511441">Container</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="25%" id="mcps1.3.4.2.8.2.2.2.4.1.2"><p id="en-us_topic_0045853755__p6916111514447">Key</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="55.00000000000001%" id="mcps1.3.4.2.8.2.2.2.4.1.3"><p id="en-us_topic_0045853755__p3916111594412">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="en-us_topic_0045853755__row49161115194414"><td class="cellrowborder" rowspan="2" valign="top" width="20%" headers="mcps1.3.4.2.8.2.2.2.4.1.1 "><p id="en-us_topic_0045853755__p791616152446">Condition</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.4.2.8.2.2.2.4.1.2 "><p id="en-us_topic_0045853755__p16916101534416">KeyPrefixEquals</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="55.00000000000001%" headers="mcps1.3.4.2.8.2.2.2.4.1.3 "><p id="en-us_topic_0045853755__p591681519441">Object name prefix on which the redirection rule takes effect. When a request is sent for accessing an object, the redirection rule takes effect if the object name prefix matches the value specified for this parameter.</p>
|
|
<p id="en-us_topic_0045853755__p58120199">For example, to redirect the request for object <strong id="en-us_topic_0045853755__b4757156775">ExamplePage.html</strong>, set the <strong id="en-us_topic_0045853755__b6131444151815">KeyPrefixEquals</strong> to <strong id="en-us_topic_0045853755__b6763656177">ExamplePage.html</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="en-us_topic_0045853755__row189161115104413"><td class="cellrowborder" valign="top" headers="mcps1.3.4.2.8.2.2.2.4.1.1 "><p id="en-us_topic_0045853755__p1791601516448">HttpErrorCodeReturnedEquals</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.4.2.8.2.2.2.4.1.2 "><p id="en-us_topic_0045853755__p11916171512441">HTTP error codes upon which the redirection rule takes effect. The specified redirection is applied only when the error code returned equals the value specified for this parameter.</p>
|
|
<p id="en-us_topic_0045853755__p40599109">For example, if you want to redirect requests to <strong id="en-us_topic_0045853755__b9362122010">NotFound.html</strong> when HTTP error code 404 is returned, set <strong id="en-us_topic_0045853755__b4424194512012">HttpErrorCodeReturnedEquals</strong> to <strong id="en-us_topic_0045853755__b64812507207">404</strong> in <strong id="en-us_topic_0045853755__b881723201">Condition</strong>, and set <strong id="en-us_topic_0045853755__b168152162017">ReplaceKeyWith</strong> to <strong id="en-us_topic_0045853755__b0810262017">NotFound.html</strong> in <strong id="en-us_topic_0045853755__b198182132012">Redirect</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="en-us_topic_0045853755__row12916115134418"><td class="cellrowborder" rowspan="5" valign="top" width="20%" headers="mcps1.3.4.2.8.2.2.2.4.1.1 "><p id="en-us_topic_0045853755__p791671511442">Redirect</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.4.2.8.2.2.2.4.1.2 "><p id="en-us_topic_0045853755__p891613152448">Protocol</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="55.00000000000001%" headers="mcps1.3.4.2.8.2.2.2.4.1.3 "><p id="en-us_topic_0045853755__p3320144784713">Protocol used for redirecting requests. The value can be <strong id="en-us_topic_0045853755__b12336184372115">http</strong> or <strong id="en-us_topic_0045853755__b15760124532113">https</strong>. If this parameter is not specified, the default value <strong id="en-us_topic_0045853755__b125449352210">http</strong> is used.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="en-us_topic_0045853755__row1091651554417"><td class="cellrowborder" valign="top" headers="mcps1.3.4.2.8.2.2.2.4.1.1 "><p id="en-us_topic_0045853755__p1491691513447">HostName</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.4.2.8.2.2.2.4.1.2 "><p id="en-us_topic_0045853755__p1691619151449">Host name to which the redirection is pointed. If this parameter is not specified, the request is redirected to the host from which the original request is initiated.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="en-us_topic_0045853755__row149161015184410"><td class="cellrowborder" valign="top" headers="mcps1.3.4.2.8.2.2.2.4.1.1 "><p id="en-us_topic_0045853755__p109167156447">ReplaceKeyPrefixWith</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.4.2.8.2.2.2.4.1.2 "><p id="en-us_topic_0045853755__p130175665316">The object name prefix used in the redirection request. OBS replaces the value of <strong id="en-us_topic_0045853755__b13222155116129">KeyPrefixEquals</strong> with the value you specified here for <strong id="en-us_topic_0045853755__b19325135517124">ReplaceKeyPrefixWith</strong>.</p>
|
|
<p id="en-us_topic_0045853755__p56931718544">For example, to redirect requests for <strong id="en-us_topic_0045853755__b1831612161620">docs</strong> (objects in the <strong id="en-us_topic_0045853755__b618982514175">docs</strong> directory) to <strong id="en-us_topic_0045853755__b186571406176">documents</strong> (objects in the <strong id="en-us_topic_0045853755__b1526918742219">documents</strong> directory), set <strong id="en-us_topic_0045853755__b1083852416222">KeyPrefixEquals</strong> to <strong id="en-us_topic_0045853755__b676382832216">docs</strong> under <strong id="en-us_topic_0045853755__b147931231145710">Condition</strong> and <strong id="en-us_topic_0045853755__b125215412317">ReplaceKeyPrefixWith</strong> to <strong id="en-us_topic_0045853755__b109571083236">documents</strong> under <strong id="en-us_topic_0045853755__b1239154719571">Redirect</strong>. This way, requests for object <strong id="en-us_topic_0045853755__b132441144152319">docs/a.html</strong> will be redirected to <strong id="en-us_topic_0045853755__b1269195852313">documents/a.html</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="en-us_topic_0045853755__row15916111519446"><td class="cellrowborder" valign="top" headers="mcps1.3.4.2.8.2.2.2.4.1.1 "><p id="en-us_topic_0045853755__p1391611518441">ReplaceKeyWith</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.4.2.8.2.2.2.4.1.2 "><p id="en-us_topic_0045853755__p527545675416">The object name used in the redirection request. OBS replaces the entire object name in the request with the value you specified here for <strong id="en-us_topic_0045853755__b1867410487321">ReplaceKeyWith</strong>.</p>
|
|
<p id="en-us_topic_0045853755__p17284133215413">For example, to redirect requests for all objects in the <strong id="en-us_topic_0045853755__b1479010335380">docs</strong> directory to <strong id="en-us_topic_0045853755__b1991854363814">documents/error.html</strong>, set <strong id="en-us_topic_0045853755__b11206124914383">KeyPrefixEquals</strong> to <strong id="en-us_topic_0045853755__b684918823918">docs</strong> under <strong id="en-us_topic_0045853755__b1855219124583">Condition</strong> and <strong id="en-us_topic_0045853755__b124201621123910">ReplaceKeyWith</strong> to <strong id="en-us_topic_0045853755__b3481103403917">documents/error.html</strong> under <strong id="en-us_topic_0045853755__b178362315819">Redirect</strong>. This way, requests for both objects <strong id="en-us_topic_0045853755__b1963161104020">docs/a.html</strong> and <strong id="en-us_topic_0045853755__b1195518149407">docs/b.html</strong> will be redirected to <strong id="en-us_topic_0045853755__b85962343403">documents/error.html</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="en-us_topic_0045853755__row191651510442"><td class="cellrowborder" valign="top" headers="mcps1.3.4.2.8.2.2.2.4.1.1 "><p id="en-us_topic_0045853755__p391619155443">HttpRedirectCode</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.4.2.8.2.2.2.4.1.2 "><p id="en-us_topic_0045853755__p2916131554417">HTTP status code returned to the redirection request. The default value is <strong id="en-us_topic_0045853755__b495710404329">301</strong>, indicating that requests are permanently redirected to the location specified by <strong id="en-us_topic_0045853755__b1032182516334">Redirect</strong>. You can also set this parameter based on your service needs.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<p id="en-us_topic_0045853755__p1467619110127"><strong id="en-us_topic_0045853755__b3903611183710">Example of setting a redirection rule</strong></p>
|
|
<ul id="en-us_topic_0045853755__ul1038139174318"><li id="en-us_topic_0045853755__li338149114319">Example 1: All requests for objects prefixed with <strong id="en-us_topic_0045853755__b689032911371">folder1/</strong> are automatically redirected to pages prefixed with <strong id="en-us_topic_0045853755__b53721755103718">target.html</strong> on host <strong id="en-us_topic_0045853755__b287418120385">www.example.com</strong> using HTTPS.<pre class="screen" id="en-us_topic_0045853755__screen218819216128">[
|
|
{
|
|
"Condition": {
|
|
"KeyPrefixEquals": "folder1/"
|
|
},
|
|
"Redirect":{
|
|
"Protocol": "https",
|
|
"HostName": "www.example.com",
|
|
"ReplaceKeyPrefixWith": "target.html"
|
|
}
|
|
}
|
|
]</pre>
|
|
</li><li id="en-us_topic_0045853755__li173813984316">Example 2: All requests for objects prefixed with <strong id="en-us_topic_0045853755__b11285349399">folder2/</strong> are automatically redirected to objects prefixed with <strong id="en-us_topic_0045853755__b15498184643915">folder/</strong> in the same bucket.<pre class="screen" id="en-us_topic_0045853755__screen14504104631218">[
|
|
{
|
|
"Condition": {
|
|
"KeyPrefixEquals": "folder2/"
|
|
},
|
|
"Redirect":{
|
|
"ReplaceKeyPrefixWith": "folder/"
|
|
}
|
|
}
|
|
]</pre>
|
|
</li><li id="en-us_topic_0045853755__li1113668107">Example 3: All requests for objects prefixed with <strong id="en-us_topic_0045853755__b4731321174110">folder.html</strong> are automatically redirected to the <strong id="en-us_topic_0045853755__b954124017412">folderdeleted.html</strong> object in the same bucket.<pre class="screen" id="en-us_topic_0045853755__screen1434130201117">[
|
|
{
|
|
"Condition": {
|
|
"KeyPrefixEquals": "folder.html"
|
|
},
|
|
"Redirect":{
|
|
"ReplaceKeyWith": "folderdeleted.html"
|
|
}
|
|
}
|
|
]</pre>
|
|
</li><li id="en-us_topic_0045853755__li1927143941410">Example 4: If the HTTP status code 404 is returned, the request is automatically redirected to the page prefixed with <strong id="en-us_topic_0045853755__b82451131144213">report-404/</strong> on host <strong id="en-us_topic_0045853755__b8129123618421">www.example.com</strong>.<div class="p" id="en-us_topic_0045853755__p1071710020226">For example, if you request the page <strong id="en-us_topic_0045853755__b8127133719428">ExamplePage.html</strong> but the HTTP 404 error is returned, the request will be redirected to the <strong id="en-us_topic_0045853755__b101331374424">report-404/ExamplePage.html</strong> page on the <strong id="en-us_topic_0045853755__b141331237134215">www.example.com</strong>. If the 404 redirection rule is not specified, the default 404 error page configured in the previous step is returned when the HTTP 404 error occurs.<pre class="screen" id="en-us_topic_0045853755__screen73090192214">[
|
|
{
|
|
"Condition": {
|
|
"HttpErrorCodeReturnedEquals": "404"
|
|
},
|
|
"Redirect":{
|
|
"HostName": "www.example.com",
|
|
"ReplaceKeyPrefixWith": "report-404/"
|
|
}
|
|
}
|
|
]</pre>
|
|
</div>
|
|
</li></ul>
|
|
</p></li><li id="en-us_topic_0045853755__li48239657155648"><span>Click <strong id="en-us_topic_0045853755__b34060727204810">OK</strong>.</span><p><p id="en-us_topic_0045853755__p3511597215574">After the static website hosting is effective in OBS, you can access the static website by using the URL provided by OBS.</p>
|
|
<div class="note" id="en-us_topic_0045853755__note26704308478"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="en-us_topic_0045853755__aa072561f65e0481fa7f9fc73b2fa3a92">In some conditions, you may need to clear the browser cache before the expected results are displayed.</p>
|
|
</div></div>
|
|
</p></li></ol>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="obs_03_0336.html">Static Website Hosting</a></div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script language="JavaScript">
|
|
<!--
|
|
image_size('.imgResize');
|
|
var msg_imageMax = "view original image";
|
|
var msg_imageClose = "close";
|
|
//--></script> |