|
| 1 | +--- |
| 2 | +page_title: "Using STACKIT CDN with your own domain" |
| 3 | +--- |
| 4 | +# Using STACKIT CDN with your own domain |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +This guide outlines the process of creating a STACKIT CDN distribution and configuring it to make use of an existing domain using STACKIT DNS. |
| 9 | + |
| 10 | +## Steps |
| 11 | + |
| 12 | +1. **Create a STACKIT CDN and DNS Zone** |
| 13 | + |
| 14 | + Create the CDN distribution and the DNS zone. |
| 15 | + |
| 16 | + ```terraform |
| 17 | + resource "stackit_cdn_distribution" "example_distribution" { |
| 18 | + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" |
| 19 | + config = { |
| 20 | + backend = { |
| 21 | + type = "http" |
| 22 | + origin_url = "mybackend.onstackit.cloud" |
| 23 | + } |
| 24 | + regions = ["EU", "US", "ASIA", "AF", "SA"] |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + resource "stackit_dns_zone" "example_zone" { |
| 29 | + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" |
| 30 | + name = "My DNS zone" |
| 31 | + dns_name = "myapp.runs.onstackit.cloud" |
| 32 | + contact_email = "aa@bb.ccc" |
| 33 | + type = "primary" |
| 34 | + } |
| 35 | + ``` |
| 36 | + |
| 37 | +2. **Add CNAME record to your DNS zone** |
| 38 | +
|
| 39 | + If you want to redirect your entire domain to the CDN, you can instead use an A record. |
| 40 | + ```terraform |
| 41 | + resource "stackit_dns_record_set" "example" { |
| 42 | + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" |
| 43 | + zone_id = stackit_dns_zone.example_zone.zone_id |
| 44 | + name = "cdn" |
| 45 | + type = "CNAME" |
| 46 | + records = ["${stackit_cdn_distribution.domains[0].name}."] |
| 47 | + } |
| 48 | + ``` |
| 49 | + |
| 50 | +3. **Create a STACKIT CDN Custom Domain** |
| 51 | + ```terraform |
| 52 | + # Create a CDN custom domain |
| 53 | + resource "stackit_cdn_custom_domain" "example" { |
| 54 | + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" |
| 55 | + distribution_id = stackit_cdn_distribution.example_distribution.distribution_id |
| 56 | + name = "${stackit_dns_record_set.example.name}.${stackit_dns_zone.dns_name}" |
| 57 | + } |
| 58 | + ``` |
| 59 | + |
| 60 | + Now, you can access your content on the url `cdn.myapp.runs.onstackit.cloud`. |
0 commit comments