Setting Up a Custom Domain
Sometimes you might want to use your own custom domain name instead of the rather generic ones provided by default for your S3 compatible Object Storage. The S3 Object Storage is available only via TLS encrypted transport (https
) in order to improve security. CNAME
resource records only work with unencrytped transport and are not supported without showing up certificate errors.
Bascially, you'll need to set up a proxy server passing the requests to the S3 Object Storage system and als providing the TLS certificate. You could, for example, use Cloudflare. Please be cautious setting up such a proxy, so that it doesn't change the requests.
Cloudflare Example
This guide assumes that you already have a domain on Cloudflare.
This only works for publicly shared objects. See: Share Object Storage with public
Cloudflare makes it easy to get a bucket publicly accessible on your own domain name.
Prepare Bucket
First, make sure you have created the bucket and enabled public sharing for the bucket the Contabo Object Storage Panel. Note: When public sharing is enabled for a bucket, all objects inside the first level of the bucket are also automatically publicly shared (even when not shared explicitly). However, this is not true for objects in folders inside the bucket. Enable public sharing for each folder as well if you want their content to be also publicly accessible.
Take note of the public sharing URL. It contains your unique tenant ID which we will need later. The URL looks like this, for example: https://eu2.contabostorage.com/5b5de0931f634e9096479dbc6e65b207:bucket
DNS
Once you are set, sign into the Cloudflare Dashboard and select your domain. Go to the DNS panel first and select Add record. Choose CNAME as type, enter a name of your choice ("objects" in this example) and enter the target. This is the first part of the public sharing URL ("eu2.contabostorage.com" here).
The final DNS record should look like this:
SSL Mode
To avoid infinite redirects, set the SSL mode in Cloudflare. Go to Rules → Configuration Rules in the Cloudflare Dashboard and select Create rule. There, select "Hostname" as Field, "equals" as Operator and your hostname as Value, "objects.example.com" in our example:
Scroll down to add SSL as setting and set it to "Full":
Rewrite URL
Next up is a rewrite rule to shorten the final URL. Go to Rules → Transform Rules in the Cloudflare Dashboard, select Create transform rule and Rewrite URL:
We set the rule to match all requests for the newly-added hostname so select "Hostname" as Field, "equals" as Operator and your hostname as Value, "objects.example.com" in our example.
Select Rewrite to... as Then... action, make sure it is set to "Dynamic" and enter this pattern:
concat("/<your unique tenant ID>:<bucket>",http.request.uri.path)
With this rewrite rule, we won't need to put the tenant ID and bucket name in the URL anymore. Cloudflare will do it for us when proxying the request to the Object Storage. With this, we went from the long original URL https://eu2.contabostorage.com/5b5de0931f634e9096479dbc6e65b207:bucket/image.jpg
to a much shorter: https://objects.example.com/image.jpg