Hosting static website with Object Storage & CDN
This document will cover how to host a static website using KakaoCloud Object Storage and CDN.
- Estimated time: 30 minutes
- User environment
- Recommended OS: MacOS, Ubuntu
- Region: kr-central-2
- Recommended OS: MacOS, Ubuntu
Step 1. Create bucket in Object Storage
Create a bucket to use Object Storage. Once you create a bucket, you can upload data in units of objects. Create a bucket to upload a website.
-
Go to KakaoCloud Console > Object Storage.
-
Click the [Create new bucket] button on the Buckets tab.
-
In the Create New Bucket pop-up window, enter the information as follows and click the [Create] button.
Type Name Encryption Hot web-hands-on Not in use infoFor detailed instructions on creating a bucket in the Object Storage service, please refer to Object Storage > Create Bucket.
Step 2. Set access to created bucket
You can create a bucket and proceed with setting access rights and life cycles for objects. You need to modify the access rights to Allow Public Access so that external users can access the website. Here's how to allow public access to a bucket:
- Go to KakaoCloud Console > Object Storage > Bucket List and select a bucket.
- Go to Permission tab > Access control and click the [Configure access] button.
- In the pop-up window, click Allow public access (Read only), and then click the [Save] button.
- In the pop-up, click the [OK] button to allow public access.
Allowing public access from all IP addresses may cause security issues. Therefore, please set separate access-allowed IP settings.
Step 3. Create example static website
Create a web page to use as an example for the guide. Open a terminal in your local environment and enter the example code below to create an example website.
Create example static website
-
Create a working directory.
Create directorymkdir -p ~/Downloads/static-web/images
-
Create an access web html file.
Create html filecat <<EOF > ~/Downloads/static-web/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>kc-hands-on test page</title>
</head>
<body>
<h1>My test page</h1>
<img src="images/hands-on.png" alt="My test image">
</body>
</html>
EOF -
Download the image file that will be displayed on the example site.
Download image filecurl -o ~/Downloads/static-web/images/hands-on.png \
https://objectstorage.kr-central-2.kakaocloud.com/v1/fe631cd1b7a14c0ba2612d031a8a5619/public/docs/object-storage-cdn-static-website/kakaocloud-docs.png
Upload example site
- Go to KakaoCloud Console > Object Storage > Bucket List and select a bucket.
- Go to Objects tab and click the [Upload file] button.
- Click the [Add folder] button to upload the
~/Downloads/static-web
directory you worked on earlier. - Click the [Upload] button to upload the folder to the bucket.
Access tp example site
- Go to KakaoCloud Console > Object Storage > Bucket List and select a bucket.
- Go to Objects tab and select the uploaded
static-web
directory to check the web page files. - Select the [More] icon of the
index.html
file > Copy object URL. - Paste the copied URL into the browser, then access and check the page created as an example.
Step 4. Set up CDN
Here are the steps to create and set up a CDN service.
Create CDN service
- Select the CDN menu in the KakaoCloud Console.
- Click the [Create Service] button in the Service List.
- Enter the CDN information in Step 1: Service and Origin Server and click the [Next] button.
Information on the service and origin server to set
Item | Value |
---|---|
Service name | web-hands-on |
Host Server | KC CDN |
Origin Server | KC Object Storage - Bucket: Select web-hands-on |
Origin Server Protocol | HTTPS |
Origin Server Port Number | 443 |
Origin Server Path (Optional) | /static-web |
Gzip Compression | Enable |
- Enter the information in Step 2: Cache and Step 3: Access Control, and then click the [Next] button.
- For this exercise, keep the default values.
- Review the information in Step 4: Review, and then click the [Create] button to complete the creation of
web-hands-on
.
- Click the [Previous] button to go to the previous step and edit the information.
-
Check the generated CDN service name in the Service list of CDN, and then select the [More] icon > Start or Restart.
-
Click the [Start] button in the CDN Service Start pop-up window. 8. Confirm the service start with the message CDN service was successfully created’ at the top.
Check service domain access
CDN > Service list Copy the service domain of the CDN created and confirm normal access to the test page in a web browser.
http://{CDN service domain}/index.html
Access to test page