OBS allows you to access static websites hosted by OBS using user-defined domain names. This section uses a specific scenario as an example to describe how to use a user-defined domain name to configure static website hosting. For a basic understanding of the concepts and operations about the static website hosting on OBS, see Configuring Static Website Hosting.
Company A has a large number of files to archive but it does not want to put the time and effort into its storage resources. Therefore, the company subscribes to OBS for hosting static websites and expects that the usernames under the company account can access the static resources through a user-defined domain name. See Figure 1.
Create a bucket on OBS Console first, for storing static website resources, and enable static website hosting for this bucket. Then use DNS to create and configure domain name hosting. The procedure is as follows:
Table 1 describes the data to be planned before this configuration.
Item |
Description |
Example |
---|---|---|
User-defined domain name |
Indicates user's own domain name. |
www.example.com |
Static website homepage |
Indicates the index page that is returned when you access a static website, that is, the homepage. |
index.html |
404 error page |
When an incorrect static website path is accessed, the 404 error page is returned. |
error.html |
<html> <head> <title>Hello OBS!</title> <meta charset="utf-8"> </head> <body> <p>Welcome to use OBS static website hosting.</p> <p>This is the homepage.</p> </body> </html>
<html> <head> <title>Hello OBS!</title> <meta charset="utf-8"> </head> <body> <p>Welcome to use OBS static website hosting.</p> <p>This is the 404 error page.</p> </body> </html>
If you have a registered domain name, skip this step.
If you do not have a registered domain name, register one with a registrar of your choice. In this scenario, the example domain name www.example.com is used. In practice, you need to replace the domain name with the one you actually planned.
There are no special requirements on bucket names. Create a bucket for storing static website files as prompted. The following example describes how to create a bucket named example:
According to different website access frequency and response speed requirements, you can also choose Warm or Cold. For details about storage classes, see Storage Classes Overview.
Prepare the static website files to be uploaded and perform the following steps to upload all static website files to bucket example.
You can also click add file in the Upload Object area to select files.
After uploading the static website files, you need to configure the static website hosting function for the bucket.
You can also redirect the entire static website to another bucket or domain name. For details, see Configuring Redirection.
You can also configure redirection rules based on service requirements to implement website content redirection. For details, see Configuring Static Website Hosting.
To bind a user-defined domain name to a bucket, perform the following steps:
To facilitate unified management of your user-defined domain names and static websites and implement cloud-based services, directly manage your user-defined domain names on DNS. After the hosting is configured, you can perform subsequent management of the domain name on DNS, including managing record sets and PTR records, as well as creating wildcard DNS records.
Alternatively, you can add a CNAME record to the DNS at the DNS registrar, mapping to the static website domain name hosted by the bucket.
To create and configure domain name hosting on DNS, perform the following steps:
Use the root domain name example.com created in Step 1 as the name of the public zone to be created. For details about how to create a public zone, see "Step 1. Create a Public Zone" in section "Routing Internet Traffic to a Website" of the Domain Name Service User Guide.
In DNS, add a record set for the sub-domain name www.example.com of the hosted domain name, to map the CNAME of the sub-domain name to the static website domain name hosted by OBS. Configure the parameters as follows:
For details, see section "Adding a CNAME Record Set" in the Domain Name Service User Guide.
At your domain name registrar, change the DNS server address in the NS record of the root domain name to the cloud DNS server address. The specific address is the NS value of the public zone in DNS.
For details about how to change the addresses of the DNS servers, see "Step 4. Change DNS Servers of the Domain Name" in section "Routing Internet Traffic to a Website" of the Domain Name Service User Guide.
The address change will be effective within 48 hours. The actual time taken varies depending on the domain name registrar.
In some conditions, you may need to clear the browser cache before the expected results are displayed.
If you need to update a static file, such as a picture, a piece of music, an HTML file, or a CSS file, you can re-upload the static file.
By default, if two files in a path share one name, the newly uploaded file overwrites the original one. To prevent files from being overwritten, you can enable the versioning function. Versioning allows you to keep multiple versions of a static file, so that you can retrieve and restore history versions conveniently. With versioning enabled, data can be restored rapidly when accidental operations or application faults occur. For detailed information about versioning, see chapter Versioning Overview.