Getting started with Yandex Cloud CDN
Configure content sharing via a CDN using a Object Storage bucket as an example:
- 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 usually the company that registered your domain.
-
Go to the management console
and log in to Yandex Cloud or create an account if you do not have one yet. -
If you do not have a folder yet, create one:
-
In the management console
, select the appropriate cloud in the list on the left. -
At the top right, click
Create folder. -
Enter the folder name. The naming requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
(Optional) Enter a description of the folder.
-
Select Create a default network. This will create a network with subnets in each availability zone. Within this network, a default security group will be created, inside which all network traffic is allowed.
-
Click Create.
-
-
Go to the folder page 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 a Object Storage bucket yet:
- Create a bucket.
- Enable public access to the objects in the bucket and the object list.
- Upload content to the bucket.
Create a CDN resource
-
Go to the folder page 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 the bucket created in Object Storage.
-
Domain names for content distribution: Specify the primary domain name that you will use in your website links to content posted on the CDN, e.g.,
cdn.example.com
.Alert
You cannot change the primary domain name used for content distribution after creating a CDN resource.
-
Under Additional:
-
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. The schema (http
orhttps
) does not need to be specified. Here is an example:my-bucket.storage.yandexcloud.net
Alert
If an incorrect
Host
header is configured, Object Storage will return errors in response to CDN server requests.
-
-
-
Click Create.
Upload your content to the CDN
Tip
We recommend that you preload large content to the CDN (for example, files larger than 200 MB). This is an optional step. If you skip uploading content at this point, it will be uploaded to the CDN automatically when a user tries to access it for the first time.
To preload content to CDN servers:
-
Go 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, e.g.:
/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 URL generated on the
.edgecdn.ru
domain to the clipboard. -
Go to your domain's DNS settings on the site of your DNS hosting provider.
-
Edit the appropriate CNAME record so that it points to the previously copied URL on the
.edgecdn.ru
domain. For example, if the domain name you specified when creating your CDN resource iscdn.example.com
, you need to create or replace an existing record forcdn
with the following CNAME record: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 until the DNS records are updated. This might take a few hours.
-
Make sure that the
cdn
CNAME record in the DNS server's cache points to the URL generated by the service (e.g.,cl-********.edgecdn.ru
). -
Try opening the site's URL in the browser, for example:
http://cdn.example.com/index.html