---
title: "Put a site behind the CDN"
description: "Create a distribution in front of your origin, add your domain with a Web Certificates certificate, and CNAME it."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.ezghcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Put a site behind the CDN

1. Get a certificate for your domain in Web Certificates, in the project the
   distribution will be in, and wait until it's issued. With the domain's zone in EZGH DNS,
   `--dns-zone auto` creates the validation records for you; otherwise add the records
   `ezgh certificates get` shows:

   ```sh
   ezgh certificates request example.com '*.example.com' --name example-com --dns-zone auto --wait
   ```

2. Create the distribution, with its origin and your domain:

   ```sh
   ezgh cdn distributions create --name shop \
     --origin-host shop-lb.example.com \
     --domain www.example.com=crt_2m9x0a7qpe4k
   ```

   Its `defaultHostname`, such as `d4k2m9x0a7qpe.ezghcdn.com`, serves at once. Check your site
   there first: `curl https://d4k2m9x0a7qpe.ezghcdn.com/`.

3. Create a CNAME record from your domain to the default hostname:

   | Name | Type | Value |
   | --- | --- | --- |
   | `www.example.com` | `CNAME` | `d4k2m9x0a7qpe.ezghcdn.com` |

   A zone's apex (`example.com`) can't hold a CNAME; serve it from `www` and redirect, or use your
   DNS provider's CNAME flattening.

4. Wait for `status` to be `deployed`, then check it answers:

   ```sh
   ezgh cdn distributions get cdn_4k2m9x0a7qpe
   curl https://www.example.com/cdn-cgi/trace
   ```

In the API, [CreateDistribution](/cdn-api/CreateDistribution/) takes the same:

```json
{
  "name": "shop",
  "origin": { "host": "shop-lb.example.com", "protocol": "https" },
  "domains": [{ "hostname": "www.example.com", "certificateId": "crt_2m9x0a7qpe4k" }]
}
```

To add a domain later, read the distribution with [GetDistribution](/cdn-api/GetDistribution/),
add it to `domains`, and send the whole document to [UpdateDistribution](/cdn-api/UpdateDistribution/)
with the `ETag` you read as `If-Match`, or run
`ezgh cdn distributions update cdn_4k2m9x0a7qpe --domain www.example.com=crt_2m9x0a7qpe4k --domain shop.example.com=crt_2m9x0a7qpe4k`
(`--domain` replaces the list).

Source: https://docs.ezghcloud.com/cdn/guides/put-a-site-behind-the-cdn/index.mdx
