# Use Custom Domains


This guide covers the steps to use your own domain instead of RudderStack domains for the following use cases:

- [Serving the JavaScript SDK]({{< ref "user-guides/how-to-guides/custom-domains/serve-js-sdk.md" >}})
- [Source configuration response]({{< ref "user-guides/how-to-guides/custom-domains/fetch-source-config.md" >}})
- [Sending events to the RudderStack backend (data plane)]({{< ref "user-guides/how-to-guides/custom-domains/send-events.md" >}})

Setting up custom domains for the above use cases can help you adhere to your Content Security Policy (CSP), reduce the impact of adblockers, and satisfy any compliance-related requirements.

{{< info >}}
The steps and examples in this guide are applicable for [AWS CloudFront](https://aws.amazon.com/cloudfront/). However, the settings should be similar regardless of your CDN.
{{< /info >}}

## Setup overview

{{< warning >}}
You must have access to your domain’s DNS settings and your CDN settings.
{{< /warning >}}

Create a new distribution by following these steps:

1. Log in to your [AWS console](https://aws.amazon.com/console/).
2. Click **Services** and go to **Network & Content Delivery** > **CloudFront**.
3. Click **Create a CloudFront distribution**.

The following table gives a high-level overview of the required cache policy, origin request policy, and response headers policy:

| Scenario | Cache policy | Origin request policy | Response headers policy (optional) |
| :------| :--------| :-----------| :----- |
| [Serve the JavaScript SDK]({{< ref "user-guides/how-to-guides/custom-domains/serve-js-sdk.md" >}}) | `CachingOptimized` | [Origin request policy settings]({{< ref "user-guides/how-to-guides/custom-domains/serve-js-sdk.md#sdk-origin-request-policy-settings" >}}). |  `None` | 
| [Serve source configuration]({{< ref "user-guides/how-to-guides/custom-domains/fetch-source-config.md" >}})  | See [Cache policy settings]({{< ref "user-guides/how-to-guides/custom-domains/fetch-source-config.md#cache-policy-settings" >}})  | See [Origin request policy settings]({{< ref "user-guides/how-to-guides/custom-domains/fetch-source-config.md#source-origin-request-policy-settings" >}}). | `CORS-With-Preflight` | 
| [Send events to data plane]({{< ref "user-guides/how-to-guides/custom-domains/send-events.md" >}}) | `CachingDisabled` | See [Origin request policy settings]({{< ref "user-guides/how-to-guides/custom-domains/send-events.md#event-origin-request-policy-settings" >}}). | `CORS-With-Preflight` | 

## Domains to proxy

{{< info >}}
**Why do I need to set up a proxy?**

Setting up a proxy is not required to just solve the events delivery issue. It's also important if you want to use [server-side cookies]({{< ref "sources/event-streams/sdks/rudderstack-javascript-sdk/server-side-cookies.md" >}}), rely on `document.referrer`, or navigate through any other restrictions imposed by modern browsers.
{{< /info >}}

The following table lists the three domains that you need to proxy via your own domain to successfully load the SDK and route the events to the RudderStack backend (data plane).

| Domain | Use case |
| :---------| :-----------|
| `cdn.rudderlabs.com` | To load the [JavaScript SDK]({{< ref "sources/event-streams/sdks/rudderstack-javascript-sdk/_index.md" >}}). |
| `api.rudderstack.com` | To fetch the source configuration based on the source [write key]({{< ref "get-started/introduction/glossary.md#write-key" >}}). |
| `DATA_PLANE_URL` | To send events to RudderStack. See the [Dashboard Overview]({{< ref "dashboard-guides/_index.md#connections" >}}) guide for more information on obtaining your data plane URL. | 

For each domain, you will need to create a CDN distribution and add a CNAME record in your domain for the distribution domain.

{{< warning >}}
To use your own domain for the above endpoints, you will need to route the traffic through your CDN for which you will incur charges.
{{< /warning >}}

## FAQ

#### Why am I seeing CORS errors after setting up custom domains?

CORS errors usually indicate misconfigured CDN distribution settings, not an SDK defect. Verify each distribution uses the origin request policies and `CORS-With-Preflight` response headers policy described in this guide — especially for [Fetch Source Configuration]({{< ref "user-guides/how-to-guides/custom-domains/fetch-source-config.md" >}}) and [Send Events]({{< ref "user-guides/how-to-guides/custom-domains/send-events.md" >}}). 

Confirm in the browser **Network** tab that SDK, source configuration, and event requests route through your custom domains.

#### Can I overcome ad blockers by serving the JavaScript SDK on my domain?

Many popular ad blockers block specific SDK-related downloads and API calls based on the domain name and URL. You can serve the SDK on your CDN to circumvent this issue.

<br />

