Overview
In our current setup, we utilize Cloudflare to manage DNS for our website and various web applications. Recently, management has requested the integration of a custom domain for RudderStack. This requires access to both the DNS and CDN settings.
Configuring DNS in Cloudflare
To set up the custom domain, you can configure Cloudflare DNS to proxy requests from api.ourdomain.com to api.rudderlabs.com. However, you may encounter an SSL error (526: Invalid SSL certificate) during this process, despite having valid certificates. This issue can arise when using the Full or Full (Strict) SSL options in Cloudflare.

Suggested Solution: Using Amazon CloudFront
RudderStack documentation recommends leveraging Amazon CloudFront to create a distribution for better flexibility. This might involve reconfiguring your entire DNS setup to utilize AWS CloudFront instead of Cloudflare.
Can Cloudflare Work?
Yes, it is possible to achieve this with Cloudflare. One effective method is to implement a Cloudflare Worker to handle the proxying of requests. Below is an example of how to set up a Cloudflare Worker for this purpose:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const url = new URL(request.url);
const ORIGINS = {
'api.ourdomain.com': 'api.rudderlabs.com',
};
// Check if the incoming hostname matches our defined origins
if (url.hostname in ORIGINS) {
url.hostname = ORIGINS[url.hostname];
// Proxy the request to the target origin
return fetch(url.toString(), request);
}
// If no match, return the original request
return fetch(request);
}
Conclusion
While Cloudflare can be configured to work with RudderStack, using Amazon CloudFront may provide a more robust solution. Evaluate your needs and choose the option that best fits your infrastructure requirements.
