How to get started with Yandex Cloud CDN
Use an Object Storage bucket to demonstrate how to set up content delivery over a CDN:
- Create a CDN resource.
- Upload your content to the CDN.
- Set up a CNAME record for your domain.
- Test the CDN.
Getting started
-
Make sure you have a domain name and can access the DNS settings on the website of your DNS hosting provider. This is typically your domain registrar.
-
Go to the management console
and log in to Yandex Cloud or sign up if not signed up yet. -
If you do not have a folder yet, create one:
-
In the management console
, select the appropriate cloud from the list on the left. -
At the top right, click Create folder.
-
Give your folder a name. The naming requirements are as follows:
- It must be from 2 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
Optionally, specify the description for your folder.
-
Select Create a default network. This will create a network with subnets in each availability zone. Within this network, you will also have a default security group, inside which all network traffic will be allowed.
-
Click Create.
-
-
Navigate to the folder dashboard and select Cloud CDN.
-
If the CDN provider is not activated yet, click Activate provider. A connection will be established automatically.
If you do not see the Activate provider button and you can create resources and origin groups, it means that the provider is already activated. Proceed to the next step.
-
If you do not have an Object Storage bucket yet:
- Create a bucket.
- Enable public access to the objects in the bucket and the object list.
- Upload your content to the bucket.
Create a CDN resource
-
Navigate to the folder dashboard and select Cloud CDN.
-
In the CDN resources tab, click Create resource.
-
Configure your CDN resource as follows:
-
Content query: Select
From one origin
. -
Origin type: Select
Bucket
. -
Bucket: Select your Object Storage bucket.
-
Domain names for content distribution: Specify the primary domain name you will use in your website links to CDN-hosted content, e.g.,
cdn.example.com
.Alert
You cannot change the primary domain name used for content distribution after creating a CDN resource.
-
Under Additional settings:
-
In the Origin request protocol field, select
HTTP
. -
In the Host header field, select
Custom
. -
In the Header value field, specify the domain name from the bucket URL in
<bucket_name>.storage.yandexcloud.net
format, omitting the schema (http
orhttps
). Here is an example:my-bucket.storage.yandexcloud.net
Alert
If the
Host
header is misconfigured, Object Storage will return errors in response to CDN server requests.
-
-
-
Click Create.
Upload your content to the CDN
Tip
We recommend preloading large content to the CDN, e.g., files larger than 200 MB. This is an optional step. If skipped, the CDN will load the content automatically when a user tries to access it for the first time.
To preload content to CDN servers:
-
Navigate to the Content tab.
-
Click Preload content.
-
In the File path field, enter the names of the files stored in the bucket, omitting the bucket name. See an example below:
/index.html /static/styles.css /static/app.js
-
Click Preload content.
Set up a CNAME record for your domain
-
In the Overview tab, under DNS settings, copy the generated URL in the
.edgecdn.ru
domain. -
Navigate to your domain DNS settings on the website of your DNS hosting provider.
-
Edit the relevant CNAME record so that it points to the previously copied URL in the
.edgecdn.ru
domain. For example, if the domain name you specified when creating your CDN resource iscdn.example.com
, you need to create the following CNAME record or use it to replace the current record forcdn
:cdn CNAME cl-********.edgecdn.ru.
Note
Do not use an ANAME resource record with domain names for content distribution; otherwise, the end user will get a response from a CDN server not linked to the user's geolocation. The response will always be the same for all users.
Test the CDN
-
Wait for the DNS records to update. This may take several hours.
-
Make sure the
cdn
CNAME record in the DNS server's cache points to the generated URL, e.g.,cl-********.edgecdn.ru
. -
Open the website in your browser to make sure it is working. Here is an example:
http://cdn.example.com/index.html