Cloud Foundry, CloudFlare and custom domains

CloudFlare is a Content Deliery Network and distributed DNS system; Cloud Foundry is a Platform as a Service.

Routing custom top-level domains (e.g. and custom subdomains (e.g. to an app running on a Cloud Foundry instance can be achieved using CloudFlare as a DNS provider as follows:

Hosting an application on a Cloud Foundry instance

Sign up for an account with a Cloud Foundry provider (e.g. Pivotal Web Services) and the install the Cloud Foundry CLI.

Using the CLI, login and target your org and space:

$ cf api <e.g.>
$ cf login
$ cf target -o my-org -s my-space

From the working directory of your application, push it to Cloud Foundry:

$ cd my-app-dir/
$ cf push my-app

Mapping custom domains to your application

Create the domain and map the route to your application (see Cloud Foundry documentation for additional information):

$ cf create-domain my-org
$ cf map-route my-app

Configuring DNS in CloudFlare

Sign up for a CloudFlare account.

Sign in to your account, and go to the DNS page for your domain (e.g

Add a CNAME entry for the domain to point to the default application route provided by Cloud Foundry. For example, on Pivotal Web Services, this url would look like

CloudFlare uses CNAME Flattening to be able to utilize a CNAME entry for both custom top-level domains (e.g. and custom subdomains (e.g.

Once this DNS record has propagated (anywhere from a few minutes to 24 hours) you should be able to access your application at both the Cloud Foundry provided url (e.g. and your custom domain