Skip to content

Put a site behind the CDN

Create a distribution in front of your origin, add your domain with a Web Certificates certificate, and CNAME it.

Updated View as Markdown
  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:

    ezgh certificates request example.com '*.example.com' --name example-com --dns-zone auto --wait
  2. Create the distribution, with its origin and your domain:

    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:

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

In the API, CreateDistribution takes the same:

{
  "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, add it to domains, and send the whole document to 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).

Navigation

Type to search…

↑↓ navigate↵ selectEsc close