---
title: Use your own CDN or WAF
related:
  - https://docs.kentico.com/documentation/developers-and-admins/configuration/website-channel-management.md
  - https://docs.kentico.com/documentation/developers-and-admins/deployment/deploy-to-the-saas-environment/manage-saas-deployments.md
  - https://docs.kentico.com/documentation/developers-and-admins/configuration/saas-configuration.md
  - https://docs.kentico.com/documentation/developers-and-admins/saas/saas-service-plans.md
  - https://docs.kentico.com/documentation/developers-and-admins/security-guidelines/web-application-firewall.md
---

> **Documentation indexes**
> The indexes below list current page URLs with titles and descriptions. Links on this page point to the Markdown versions of the linked pages.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

By default, all traffic to projects in the SaaS environment passes through the Xperience CDN (the Cloudflare CDN provided by Kentico), a content delivery network (CDN) with a web application firewall (WAF) managed by Kentico. If your organization already runs its own CDN or WAF, for example, to apply its own security rules, caching policies, or analytics, you can serve your domains through your own CDN or WAF instead. Projects with the _custom CDN_ add-on route visitors through your CDN or WAF directly to the application, without the Xperience CDN in between.

This page describes how to set up your CDN or WAF for a new project, how to move an existing project off the Xperience CDN, and how to protect the application from requests that bypass your CDN.

> **Tip:** **Key points**
>
> - Your CDN or WAF forwards requests to a per-environment _origin domain_ and keeps the hostname requested by the visitor in the `Host` header.
> - You add every web domain in Xperience Portal and prove ownership with a TXT record. Your CDN terminates TLS for your domains, so Kentico creates no certificates for them.
> - Existing projects move each domain off the Xperience CDN one at a time, without downtime.
> - After all domains are moved, you protect the origin with IP restrictions, client certificate validation, and by blocking the origin domain.

## How it works

A request to a project with the custom CDN add-on follows this path:

1. A visitor requests a page on your domain, for example, _www.example.com_. Your DNS record for the domain points to your CDN.
2. Your CDN or WAF applies its rules and caching, terminates TLS with its own certificate for _www.example.com_, and forwards the request to the environment's origin domain.
3. The application receives the request and serves the website channel that matches the `Host` header, _www.example.com_.

The origin domain is only the address of the application. The application identifies the requested domain from the `Host` header, so your CDN must send the hostname requested by the visitor, not the origin domain.

Compared to the Xperience CDN, the custom CDN add-on has the following differences:

- **Security and caching are your responsibility.** WAF rules, DDoS protection, caching, cache purging, and visitor IP masking are configured in your CDN. The Xperience CDN no longer applies to your domains.
- **Security events end for your domains.** The [Security events](https://docs.kentico.com/documentation/developers-and-admins/deployment/deploy-to-the-saas-environment/manage-saas-deployments.md#security-events) application in Xperience Portal covers only domains that are still served through the Xperience CDN. Use the analytics of your CDN provider instead.
- **No automatic cache purge for your domains.** After a successful deployment, [restore](https://docs.kentico.com/documentation/developers-and-admins/deployment/deploy-to-the-saas-environment/manage-saas-deployments.md#restore-from-a-restore-point), or [custom restore](https://docs.kentico.com/documentation/developers-and-admins/deployment/deploy-to-the-saas-environment/specialized-deployment-scenarios.md), Kentico purges the Xperience CDN cache of the environment. The cache of your CDN isn't purged, so visitors can get stale content until you purge the cache of your CDN.
- **Custom domains in every environment.** You can add web domains to all environments, not only PROD, STG, and CUST, so you can test your CDN setup before you go live.
- **No default web domains for new channels.** Channels created in projects with the custom CDN add-on get no default _xperience-sites.com_ website or service domain. You add your own domains.
- **One domain limit per environment.** Each environment can have up to 250 domains in total instead of the per-channel limits of other service plans.

## Prerequisites

- **Custom CDN add-on** – The custom CDN is a paid add-on for custom [service plans](https://docs.kentico.com/documentation/developers-and-admins/saas/saas-service-plans.md). To get the add-on, contact [Kentico sales](mailto:sales@kentico.com). Kentico then enables the add-on for your existing project, or creates a new project with the add-on. After the add-on is enabled, the project can't go back to the Xperience CDN.
- **Liability waiver** – Before Kentico enables the add-on, you need to sign a liability waiver. Kentico isn't responsible for DDoS attacks and other threats to domains served through your CDN.
- **Xperience by Kentico 31.11.0 or newer** – You can manage origin protection only in environments that run version 31.11.0 or newer. The application also needs to call `UseKenticoCloudOriginProtection` in its middleware pipeline. See [Register the origin protection middleware](#register-the-origin-protection-middleware).
- **A CDN or WAF that meets the requirements** – See [Configure your CDN or WAF](#configure-your-cdn-or-waf).

## Origin domain

Every environment has an origin domain in the following format:

`origin.<environment>-<project codename>.xperience-sites.com`

For example, _origin.prod-acme.xperience-sites.com_. The origin domain doesn't change during the lifetime of the project. You can find the origin domain of each environment in the **Custom CDN/WAF → Overview** application in Xperience Portal and in the last step of every domain setup.

The origin domain has a certificate managed by Kentico, which renews automatically. The application presents this certificate only when the TLS Server Name Indication (SNI) sent by your CDN is the origin domain. For any other SNI value, the application presents the default certificate of the hosting platform, which doesn't match the origin domain.

> **Note:** **The origin domain is a fallback address**
>
> While an environment has no administration domain or system email service domain of its own, the origin domain stands in for these domains. The administration is available at `https://<origin domain>/admin`, and links in system emails, such as password reset emails, point to the origin domain. Once you turn on any origin protection mechanism, these links stop working. [Content synchronization](https://docs.kentico.com/documentation/developers-and-admins/configuration/content-sync-configuration.md) from other environments of the project also targets the origin domain and fails once the origin is protected. Add your own administration and system email service domains before you protect the origin, and re-create the content synchronization connections against your own administration domain.

## Configure your CDN or WAF

Configure the following in your CDN or WAF for each domain served through your CDN or WAF:

- **Origin** – Set the origin domain of the environment as the origin (back end) of the domain. Use HTTPS on port 443 with TLS 1.2 or newer. The application accepts only HTTPS.
- **Host header** – Send the hostname requested by the visitor as the `Host` header. Don't rewrite the `Host` header to the origin domain.
- **Origin certificate** – Send the origin domain as the SNI and validate the origin certificate against the origin domain. If your CDN can't set the SNI separately from the `Host` header, accept the origin certificate without a hostname match. Don't pin the origin certificate, because Kentico renews the certificate automatically.
- **Caching** – Cache only responses that the application marks as cacheable with the `Cache-Control` header. Never cache the administration (`/admin`).
- **Request limits** – Allow request body sizes and timeouts at least as large as the largest files uploaded by your editors in the administration and in forms.
- **WAF rules** – Set up and tune the WAF rules of your CDN for Xperience. See [Web application firewall](https://docs.kentico.com/documentation/developers-and-admins/security-guidelines/web-application-firewall.md).
- **Health check endpoint** – Block requests to `/Kentico.Cloud.Health` in your CDN. Kentico uses the endpoint to monitor the application, and the Xperience CDN blocks the endpoint for visitors.
- **Redirects** – Redirect HTTP to HTTPS and send the HTTP Strict Transport Security (HSTS) header on the visitor side.
- **Cache purge** – Purge the cache of your CDN after every deployment, restore, and custom restore. Kentico purges only the Xperience CDN cache, which doesn't contain your domains.

If you plan to use [Origin protection](#origin-protection), also note the egress IP ranges of your CDN and whether your CDN can present a client certificate to the origin.

For the settings, see the documentation of your CDN or WAF provider, for example:

- Cloudflare – [Origin configuration](https://developers.cloudflare.com/ssl/origin-configuration/)
- Azure Front Door – [Origins and origin groups](https://learn.microsoft.com/en-us/azure/frontdoor/origin)
- Amazon CloudFront – [Require HTTPS for communication between CloudFront and your custom origin](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-https-cloudfront-to-custom-origin.html)
- Fastly – [Backends](https://www.fastly.com/documentation/guides/integrations/non-fastly-services/developer-guide-backends/)
- Akamai – [Origin Server](https://techdocs.akamai.com/property-mgr/docs/origin-server)

## Add domains

With the custom CDN add-on, every web domain is served through your CDN. This applies to website channel domains, email channel service domains, and the administration and system email service domains. Sending domains for emails aren't affected and work the same way as in projects without the add-on.

When you add a domain, Xperience Portal asks only for a TXT record that proves your ownership of the domain. Xperience Portal doesn't check the configuration of your CDN and doesn't create a certificate for the domain. The DNS record of your domain (for example, a `CNAME` record or the apex records provided by your CDN) points to your CDN, never directly to the origin domain.

Apex domains (_example.com_) and subdomains (_www.example.com_) are both supported. Add each apex domain and subdomain separately.

For general information about channel domains, see [Website channel management](https://docs.kentico.com/documentation/developers-and-admins/configuration/website-channel-management.md#manage-channel-domains-in-xperience-portal) and [Email channel management](https://docs.kentico.com/documentation/developers-and-admins/digital-marketing-setup/email-channel-management.md#manage-email-channel-domains-in-xperience-portal).

### Add a website channel domain

1. Open the **Channels and Domains → Channels** application in [Xperience Portal](https://docs.kentico.com/documentation/developers-and-admins/saas/xperience-portal.md).
2. Select the **Domains** action for the website channel.
3. Select **Add domain**, select the **Environment**, and enter the **Domain name**.
4. Add the displayed TXT record in your DNS provider and confirm. Xperience Portal validates the record and adds the domain to the application.
5. **Apply changes** to write the domain to the configuration of the application. Applying changes restarts the application.
6. In your CDN, configure the domain to use the origin domain displayed in the **Connect your CDN/WAF** step. See [Configure your CDN or WAF](#configure-your-cdn-or-waf).
7. Point the DNS record of your domain to your CDN.
8. (_Optional_) In the **Ping test (optional)** section of the **Connect your CDN/WAF** step, select **Send request** to check the response of your domain.
9. Confirm the step. The domain becomes active.

The first domain added to a website channel without a main domain becomes the main domain of the channel.

The ping test sends a single HTTPS request to your domain from Xperience Portal and shows the status code of the response. The test doesn't prove that your CDN is set up correctly. For example, if your CDN rewrites the `Host` header to the origin domain, your site doesn't load, but the test can still show a successful status code. Open your domain in a browser and check that the pages of your website channel load, and not the text _No website channel is running on this domain_ or the _404_ page of the hosting platform. See [Troubleshooting](#troubleshooting).

A website channel without any domain falls back to the domain stored in the channel configuration in the Xperience administration. Requests for that domain don't reach the channel, because the domain isn't added in Xperience Portal, so the channel serves no pages until you add a domain in Xperience Portal.

### Add or replace an email channel service domain or a system domain

Email channel service domains, the administration domain, and the system email service domain have one active domain each. Adding a new domain replaces the current domain.

1. Open the domain list:
   - For email channel service domains, open the **Channels and Domains → Channels** application and select the **Domains** action for the email channel.
   - For the administration and system email service domains, open the **Channels and Domains → System domains** application.
2. Select **Start domain replacement** for the active domain, or **Add domain** if the environment has no domain of that kind yet.
3. Enter the **Domain name**.
4. Add the displayed TXT record in your DNS provider and confirm. Xperience Portal validates the record and adds the domain to the application.
5. In your CDN, configure the domain to use the origin domain displayed in the **Connect your CDN/WAF** step, and point the DNS record of your domain to your CDN.
6. Confirm the step. The new domain replaces the previous domain.
7. **Apply changes** to write the new domain to the configuration of the application.

> **Note:** Until you apply changes, the configuration of the application still contains the previous domain, although the previous domain no longer exists in Xperience Portal.
>
> Confirming a new administration domain also deletes the active [content synchronization](https://docs.kentico.com/documentation/developers-and-admins/configuration/content-sync-configuration.md) connections from other environments of the project to this environment. Re-create the connections against the new administration domain. Xperience Portal keeps connections from external sources. Point the external source to the new administration domain.

An email channel without a service domain uses the service domain stored in the channel configuration in the Xperience administration.

## Migrate from the Xperience CDN

After Kentico enables the custom CDN add-on for your existing project, your existing domains keep working through the Xperience CDN. You then move the domains to your CDN one at a time. The migration is finished when no domain of the project is served through the Xperience CDN.

The **Custom CDN/WAF → Overview** application in Xperience Portal shows the progress of the migration and lists every remaining domain with its next step. Until the migration is finished, Xperience Portal displays a notice with a link to the overview.

> **Warning:** **The origin is not protected during the migration**
>
> From the moment the add-on is enabled until the migration is finished, anyone who knows the origin domain can reach the application directly, bypassing both the Xperience CDN and your CDN. You can turn on [Origin protection](#origin-protection) only after the migration is finished, so finish the migration promptly.

You can't complete domain workflows that started on the Xperience CDN before the add-on. Cancel these workflows and add the domains again through your CDN. A standard website domain workflow waiting for changes to be applied finishes with the next **Apply changes**. You can then move the domain like any other custom domain.

To migrate a project:

1. **Move your custom domains.** For each custom website, email channel service, and system email service domain:

   1. Make sure that the domain is active and has no pending changes. If needed, **Apply changes** first. Then select **Move to your CDN/WAF** for the domain. The dialog shows the origin domain of the environment.
   2. Connect the domain to your CDN, so that requests for the domain reach your CDN and your CDN forwards them to the origin domain. Depending on your provider, add the domain to your CDN, change the DNS record of the domain to point to your CDN, or both. See [Configure your CDN or WAF](#configure-your-cdn-or-waf).
   3. For website domains, open the domain in a browser and check that the pages of your website channel load through your CDN. For example, check that the response headers contain the headers added by your CDN provider. The optional ping test shows only that the domain responds, not which CDN responds. For other domains, wait until the DNS change propagates.
   4. Confirm that the DNS record of the domain already points to your CDN, and select **Move to your CDN/WAF**.

   The domain is moved immediately and the Xperience CDN stops serving the domain. The configuration of the application doesn't change, so you don't need to apply changes. You can't undo the move.
2. **Remove default website domains.** Delete the default _xperience-sites.com_ website domains. Before you delete the last domain of a website channel, [add a domain](#add-a-website-channel-domain) through your CDN.
3. **Replace default email channel service domains** with your own domains. See [Add or replace an email channel service domain or a system domain](#add-or-replace-an-email-channel-service-domain-or-a-system-domain).
4. **Replace the default system email service domain** in each environment.
5. **Replace the default administration domain** in each environment. You can replace the administration domain only after all custom domains of the environment are moved, because the Xperience CDN routes custom domains through the default administration domain.

After the last domain is moved, the migration notice disappears and you can set up [Origin protection](#origin-protection).

## Origin protection

Origin protection makes sure that only your CDN can reach the application. Without origin protection, anyone who knows the origin domain or the platform hostname of the application can bypass your CDN and its WAF rules.

You manage origin protection for each environment in the **Custom CDN/WAF → Origin protection** application in Xperience Portal. Origin protection is available after the [migration](#migrate-from-the-xperience-cdn) is finished, in environments that run Xperience by Kentico 31.11.0 or newer. The migration applies to the whole project: an environment whose domains are all moved still waits until no domain in any environment of the project is served through the Xperience CDN. Projects created with the custom CDN add-on have no migration, so origin protection is available as soon as the environment runs a supported version.

The following mechanisms are independent of each other. For full protection, turn on all three mechanisms. If some mechanism is off, Xperience Portal shows the environment as **Not fully protected** and names the mechanism that is off. If your CDN doesn't support a mechanism, leave the mechanism off.

| Mechanism                            | Description                                                                              | Restarts the application |
| ------------------------------------ | ---------------------------------------------------------------------------------------- | ------------------------ |
| IP restrictions                      | Accepts traffic only from allowed IP addresses and ranges.                               | No                       |
| Client certificate validation (mTLS) | Accepts only requests with a client certificate whose public key matches an allowed pin. | Yes                      |
| Block the origin domain              | Refuses every request whose `Host` header is the origin domain.                          | Yes                      |

> **Note:** While the origin domain still stands in for the administration or system email service domain of an environment, protecting the origin breaks the fallback. Xperience Portal shows a warning in this case. See [The origin domain is a fallback address](#origin-domain).

To protect the origin of an environment:

1. Open the **Custom CDN/WAF → Origin protection** application in Xperience Portal.
2. Select the **Environment**.
3. Turn on the mechanisms supported by your CDN and enter their values. See the following sections.
4. **Save origin protection**, and confirm with **Save**.

Xperience Portal saves all settings of the environment together and applies the settings shortly after the save. You can't save the environment again while Xperience Portal applies the previous save.

> **Warning:** The protection takes effect as soon as Xperience Portal applies the settings. Before you save, make sure that your CDN already connects from the allowed IP addresses and, with client certificate validation, presents a certificate with an allowed pin. Otherwise, your sites stop responding to visitors.

### IP restrictions

Allow the egress IP ranges of your CDN, so that requests from other sources never reach the application.

Enter the IPv4 or IPv6 addresses or CIDR ranges into **Allowed IP addresses and ranges**, one per line, up to 50 entries per environment. A single address is saved as a range of that one address (`/32` or `/128`). Kentico keeps its own platform entries, so the IP restrictions don't block deployments and availability checks.

Keep the list up to date when your CDN provider changes its IP ranges.

### Client certificate validation

If your CDN can present a client certificate to the origin (mutual TLS), the application can reject requests without the certificate.

1. Configure your CDN to present a client certificate when connecting to the origin.

2. Calculate the SPKI pin of the certificate: the Base64-encoded SHA-256 hash of the public key of the certificate (Subject Public Key Info). For example, with OpenSSL:

   ```bash
   openssl x509 -in client-certificate.pem -pubkey -noout \
       | openssl pkey -pubin -outform der \
       | openssl dgst -sha256 -binary \
       | openssl enc -base64
   ```

3. Turn on **Client certificate validation (mTLS)** and enter the pin into **SPKI pins**, one pin per line, up to 20 pins per environment.

Requests without a certificate, with a certificate outside its validity period, or with a certificate whose pin isn't in the list get the _403 Forbidden_ status code. Before your CDN rotates its client certificate, add the pin of the new certificate. Remove the old pin after the rotation.

### Block the origin domain

When you turn on **Block the origin domain**, the application refuses every request whose `Host` header is the origin domain, with the _403 Forbidden_ status code and the text _Requests to the domain '\<origin domain>' are not being processed._ Requests that come through your CDN carry your own domain in the `Host` header, so the block doesn't apply to these requests.

With the custom CDN add-on, the origin domain isn't blocked until you turn on the setting.

### Register the origin protection middleware

Client certificate validation and blocking of the origin domain run in the application. Call `UseKenticoCloudOriginProtection` in the middleware pipeline of your application, directly after `InitKentico`:

```csharp title="Program.cs"
using Kentico.Web.Mvc;
using Kentico.Xperience.Cloud;

using Microsoft.AspNetCore.Builder;

// ...

var app = builder.Build();

app.InitKentico();

// Refuses requests to blocked domains and validates client certificates
app.UseKenticoCloudOriginProtection();

app.UseStaticFiles();

// ...
```

Projects created with the `--cloud` parameter in version 31.10.0 or newer include this call by default. Register the middleware before `UseAuthentication` and any other middleware that reads the client certificate. For the recommended middleware order, see [Configure new projects](https://docs.kentico.com/documentation/developers-and-admins/development/website-development-basics/configure-new-projects.md#configure-application-startup). The settings take effect when the application starts, so changes of client certificate validation and of blocking the origin domain restart the application.

By default, the middleware also removes the client certificate forwarded by the hosting platform (the `X-ARR-ClientCert` header) from every request that the middleware doesn't refuse, even when client certificate validation is off. Application code that reads the client certificate, for example an OpenID Connect server, then doesn't get the certificate of your CDN. To keep the forwarded certificate in the request, set the `RemoveClientCertificate` option to `false`:

```csharp title="Program.cs"
app.UseKenticoCloudOriginProtection(options => options.RemoveClientCertificate = false);
```

## Monitor bandwidth usage

Traffic not cached by your CDN reaches the application, so the data sent by the application counts against the bandwidth of your service plan.

Open the **Custom CDN/WAF → Usage** application in Xperience Portal to see the data sent and received by the applications of the project in a calendar month (UTC), across all environments:

- **Outbound traffic** – Data sent by the applications. Kentico bills outbound traffic, and outbound traffic counts against the bandwidth of your plan.
- **Inbound traffic** – Data received by the applications. Kentico doesn't bill inbound traffic.

Select the current month or one of the two previous months. Months before the project was created aren't available. The page shows the outbound traffic against the bandwidth of your plan, the traffic of each environment, and the daily outbound and inbound traffic. To see the daily traffic of one environment, select the environment above the charts.

If the applications send more data than the bandwidth of your plan includes, the page shows a warning. Users with the _Tenant administrator_ [role](https://docs.kentico.com/documentation/developers-and-admins/saas/xperience-portal/reference-xperience-portal-user-roles.md) also get an email notification on the first day of the next month, with a link to the usage of the month. Exceeding the bandwidth doesn't slow down or block your sites. If your plan has no bandwidth limit, the page says so, and Xperience Portal shows no warning and sends no email. To increase the bandwidth, contact [Kentico sales](mailto:sales@kentico.com).

To reduce the data sent by the application, make sure your CDN caches static files and other cacheable responses.

## Troubleshooting

| Symptom                                                                                                                                                                                                                | Likely cause                                                                                                                                                                                                                                                                                                                                                       |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| The _404_ page of the hosting platform                                                                                                                                                                                 | The `Host` header carries a hostname not added in Xperience Portal, usually because your CDN rewrites the `Host` header.                                                                                                                                                                                                                                           |
| _200_ with the text _No website channel is running on this domain_                                                                                                                                                     | The request goes to the root path, and the `Host` header carries a system domain or an email channel service domain instead of a website domain. While the environment has no administration domain of its own, the origin domain gets the same response. Requests to other paths get a different response. Check that your CDN doesn't rewrite the `Host` header. |
| _403_ with the text _Requests to the domain '\<origin domain>' are not being processed_                                                                                                                                | The `Host` header carries the origin domain while **Block the origin domain** is on. Check that your CDN doesn't rewrite the `Host` header.                                                                                                                                                                                                                        |
| Any other _403_                                                                                                                                                                                                        | The egress IP addresses or the client certificate of your CDN don't match the origin protection settings, or the client certificate is outside its validity period.                                                                                                                                                                                                |
| A certificate error in your CDN                                                                                                                                                                                        | Your CDN validates the origin certificate against a name other than the origin domain, usually because the SNI follows the `Host` header. Send the origin domain as the SNI, or accept the certificate without a hostname match.                                                                                                                                   |
| Content synchronization or [uptime checkers](https://docs.kentico.com/documentation/developers-and-admins/deployment/deploy-to-the-saas-environment/manage-saas-deployments.md#uptime-monitoring) fail on your domains | Your CDN or WAF blocks the requests. Let the synchronization requests and the uptime checker requests through.                                                                                                                                                                                                                                                     |
