Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
WouterLemaire
Active Contributor

Introduction

I wanted to activate a custom domain on BTP for my own website https://wouter.lemaire.tech . To achieve this I followed this great step-by-step blog post of @andrew_lunde : https://community.sap.com/t5/technology-blogs-by-sap/step-by-step-guide-to-custom-domains-with-multi...

Nevertheless, I did some steps different which still made it challenging to configure:

  • I bought the domain using google domains
  • Used certbot instead of my own certificate (in companies you’ll probably have a company certificate)
  • Added MTA configuration to automatically map the domain after deploying your app

Those differences changed some steps in the flow which I documented and want to share in this blog post.

Prerequisites

Check the official SAP help documentation, this might help you to understand the flow: https://help.sap.com/docs/custom-domain/custom-domain-service/create-custom-domains?locale=en-US

You need to buy a custom domain, this is not part of this service. This service just allows you to use your custom domain (which you pay separately) to your BTP applications and services. I’m using google domains which has been migrated to Squarespace.

Install certbot: https://certbot.eff.org/instructions?ws=other&os=windows

Download the latest version of the Certbot installer for Windows at https://github.com/certbot/certbot/releases/latest/download/certbot-beta-installer-win_amd64_signed.....

Make sure your BTP account has the entitlements:

WouterLemaire_0-1711151575890.png

Create an instance of this service in your CloudFoundry Space:

WouterLemaire_1-1711151597097.png

Install the CloudFoundry CLI with the Custom Domain Self-Service plugin. The plugin can be downloaded from here: https://tools.hana.ondemand.com/#cloud

WouterLemaire_2-1711151618301.png

Once downloaded, install it by going into the folder of the plugin and run the following command in your cli: “cf install-plugin custom-domain-cli”

WouterLemaire_3-1711151644365.png

Validate if it was successful by running “cf plugins”. This will show you a list of all installed plugins including the custom domain plugin: 

WouterLemaire_4-1711151713084.png

Create your custom domain

1) Login to CloudFoundry using the cli:

WouterLemaire_5-1711151748528.png

2) Create your custom domain using the command “cf create-domain wlcf wouter.lemaire.tech”

WouterLemaire_6-1711151769099.png

You can validate if this was successful with the command “cf domains”, here you should see your domain listed:

WouterLemaire_7-1711151778954.png

3) Create a private key for your custom domain in Cloud Foundry using the command:

cf custom-domain-create-key custom-domain-wouter-lemtech-key "CN=*.wouter.lemaire.tech, EMAIL=wouter@lemaire.tech, O=lemtech, C=BE" "wouter.lemaire.tech"

  • custom-domain-create-key: command for the cf cli custom domain plugin to create the key
  • custom-domain-wouter-lemtech-key: this is the name for the key that will be created. We need this in a later phase
  • “CN=*.wouter.lemaire.tech, EMAIL=wouter@lemaire.tech, O=lemtech, C=BE” : details need to create the CSR
  • "wouter.lemaire.tech": the domain name I want to connect (more can be listed here)

WouterLemaire_8-1711151800033.png

4) Get the Certificate Signing Request (CSR) by using the created private key using the following command:

cf custom-domain-get-csr custom-domain-wouter-lemtech-key csr.pem

  • custom-domain-get-csr: cf cli custom domain command to retrieve the csr
  • custom-domain-wouter-lemtech-key: name of the private key which was created in the previous step
  • csr.pem: name of that will be used to store the csr in

WouterLemaire_9-1711151835284.png

5) Sign the CSR using certbot by running cmd as administrator from the folder where the csr.pem file is stored and run the following command:

certbot certonly --manual --csr ./csr.pem --preferred-challenges dns

WouterLemaire_10-1711151853127.png

This will give you a token which you need to use to create a TXT record in Google Domains:

WouterLemaire_11-1711151861507.png

Once you created the record, you can press enter. This might take a while but eventually provide you some certificates:

WouterLemaire_12-1711151871269.png

6) Upload the signed certificate to CloudFoundry

As I received three certificates from certbot and it was not clear which one to take so I tried merging all of them into one:

WouterLemaire_13-1711151886853.png

When uploading the combined certificate using the following command, it went in error:

cf custom-domain-upload-certificate-chain custom-domain-wouter-lemtech-key allchain.pem

WouterLemaire_14-1711151894910.png

So I tried all certificates separately and eventually the last one worked 😊

cf custom-domain-upload-certificate-chain custom-domain-wouter-lemtech-key 0001_chain.pem

  • custom-domain-upload-certificate-chain: command to upload the certificate to CloudFoundry
  • custom-domain-wouter-lemtech-key : key that I created earlier
  • 0001_chain.pem: certificate that needs to be uploaded

WouterLemaire_15-1711151908658.png

It will ask for confirmation and upload BUT not yet activate:

WouterLemaire_16-1711151918206.png

We can check if the certificate was uploaded successfully with the following command + the private key:

cf custom-domain-show-certificates custom-domain-wouter-lemtech-key

WouterLemaire_17-1711151929340.png

7) Activate the custom domain using the following command:

cf custom-domain-activate custom-domain-wouter-lemtech-key wouter.lemaire.tech

  • custom-domain-activate: command for activating
  • custom-domain-wouter-lemtech-key: private key name
  • wouter.lemaire.tech: domain to be activated

WouterLemaire_18-1711151943919.png

You can check if the active custom domains in CloudFoundry with the command: cf custom-domain-list

In my case, I have two, one main custom domain which I’ll use to continue “Wouter.lemaire.tech” but also a generic domain that allows me to use subdomains “*.wouter.lemaire.tech”. I’ll use this one later.

WouterLemaire_19-1711151955919.png

8 ) Configure DNS for custom domain

Before we can do this, we need to get the API of CloudFoundry in your subaccount. This can be done by using the command “cf api”:

WouterLemaire_20-1711151969685.png

In Google Domains, I created the following record:

WouterLemaire_21-1711151976230.png

To test if it works I used the command “nslookup Wouter.lemaire.tech”:

WouterLemaire_22-1711151982841.png

9) Map application to custom domain

Before we do, we can check the list of apps to find the connected route for each application

WouterLemaire_23-1711151994699.png

With the following command, we will map an app with the custom domain we created (this needs to be done for the approuter app as this is the access point for an application in BTP):

cf map-route <Application Name> <Custom Domain> --hostname <Application Hostname>

In my example it looks like this, without the hostname as I want it to be connected with the main domain:

cf map-route lemtech-approuter wouter.lemaire.tech

WouterLemaire_24-1711152002676.png

If you now check the list of apps, you’ll see that the route for the approuter is connected to the custom domain:

WouterLemaire_25-1711152009142.png

You can also check the list of routes:

WouterLemaire_26-1711152015149.png

10) Configure the MTA of your app

After every deploy the mapping between the route and your app will be gone and you need to do this over again. This can be done in the BTP Cockpit:

WouterLemaire_27-1711152025585.png

You can avoid this by configuring the domain in the mta.yaml file of your application as followed:

WouterLemaire_28-1711152033375.png

With this configuration you’ll keep the domain connected to your application after each deploy

That’s how it’s done 😊

Result

Try navigating to https://wouter.lemaire.tech this will open my website which is running on SAP BTP Cloud Foundry! 

Additional

Additionally I’m also want to create subdomains so I can use the custom domain for other applications. For this, I added a record in google domains as followed:

WouterLemaire_29-1711152044282.png

I have activated the custom domain “*.wouter.lemaire.tech”

WouterLemaire_30-1711152054510.png

Mapped the application BTP Service Overview with the custom domain Wouter.lemaire.tech using btp-services as hostname:

WouterLemaire_31-1711152061124.png

Result: https://btp-services.wouter.lemaire.tech/

1 Comment
Labels in this area