百度智能云

All Product Document

          Object Storage

          Static Website Trusteeship

          Basic Concept

          BOS supports users to host static website on bucket for light-weighted operation and maintenance of website. After the setting is effective, you can access to the hosting website by directly accessing to the domain name of bucket.

          Static website refers to a website that contains all static resources such as HTML and JPG, excludes server-side scripts such as PHP, JSP, or ASP.NET. Meanwhile, a statically hosted website does not support scripting on the server side.

          To deploy and manage a dynamic website, you can use Baidu Cloud Compute (BCC) or Cloud Container Engine (CCE).

          Use Mode

          Step 1: For a static website to be hosted, you need to upload the two core resources of "Index Page" and "404 Page" in the bucket:

          Index Page Settings

          A standard website usually consists of several index pages corresponding to the homepage of the website and submodules.

          BOS will return to the index page if the user fails to request to a specific page when visiting the root directory such as www.example.com in the browser address bar, or the directory ending with/such as www.example.com/folderA/.

          Web administrator can upload static resources in the root directory and subdirectories of bucket to for effect presentation when visiting the index page.

          At present, BOS supports an index page composed of html formatted files.

          404 Page Settings

          In the event of a common 404 error when visiting a static website, a designed error page will be provided by such website to give visitors a better experience.

          For a static website hosted on BOS, the web administrator can upload files in the formats of html, jpg, png, bmp, and webp as the 404 page in the root directory of bucket. When the data expected by the website visitors cannot be found, BOS will show such 404 page by default.

          Note:

          • bucket intended for static website hosting need to be set with public read permissions for anonymous user access. Therefore it is recommended not to upload confidential data to this bucket.
          • Never set meta "Content-Disposition:attachment" for the 404 page.No.404 page sets meta "Content-Disposition:attachment".

          Step 2: You can set the index page and the 404 page through BOS MMC after the administrator uploads the resources corresponding to the index page and the 404 page in the bucket.

          As shown in the figure, please fill in the resource names of the index page and the 404 page that you uploaded in the bucket, and click the "Confirm" button to make the settings take effect.

          image.png

          Note:

          • You can define the name of the index page arbitrarily according to the site management habits, such as "index.html" or "admin.html". However, you must define the same name for the resource corresponding to the index pages at all levels.
          • Please note the file formats supported by the index page and the 404 page.
          • At least one of the index page and the 404 page is filled with a name otherwise the settings will not take effect.
          • The settings of hosting page as archive type will not take effect.
          • If the resource matching the page filled in by the administrator does not exist in the bucket, it is regarded as 404.If the resource corresponding to the 404 page does not exist, it will return to the original 404 error page.
          • When the user simultaneously opens the static website hosting and mirroring back-to-source for this bucket, if the resource expected by the user does not exist, BOS will try to mirror the source first. If there is still no corresponding resource, it will follow the logic of static hosting and feedback a 404 page.

          Example

          When the user creates a bucket named website in the bj region and places the following files in it:

          • index.html in the bucket root directory
          • 404.html in the bucket root directory
          • index.html in the bucket level-2 directory website/car
          • apollo.jpg in the bucket level-2 directory website/car

          If the user enables the static website hosting function for the Website bucket, the visit behavior of the website visitor is positioned as follows:

          • When visiting www.website.bj.bcebos.com, the page is shown as index.html.
          • When visiting www.website.bj.bcebos.com/car, the page is shown as index.html.
          • When visiting www.website.bj.bcebos.com/car/apollo.jpg, the page is shown as apollo.jpg
          • When visiting www.website.bj.bcebos.com/car/dazhong.jpg, the page is shown as 404.html since the resource does not exist.

          At meanwhile, the static website hosting function also supports setting through the API. For details, please refer to the interface description as follows:

          Previous
          Photo Review
          Next
          Monitoring Service