Custom domain with CNAME

Last change on 2025-03-17 • Created on 2025-03-17 • ID: ST-F555E

Currently, it is not possible to assign a custom domain name to a Bucket. If you want to use your own domain, you can manually set up domain forwarding.

This how-to guide explains how to set up a CNAME record. Since CNAME records currently do not work unless the host header is set as the Bucket URL, this how-to guide also explains how to overwrite the host header in the following two example scenarios:

  • Via Cloudflare with the Enterprise Plan
  • Via a short code snippet at the beginning of a Python script that uses your domain

Prerequisites:

  • Your own domain
  • A Bucket with public objects

By the end of this how-to guide, all requests should get forwarded directly to the Bucket.


  1. Create a new DNS entry

    Create a new CNAME record. Point the domain at the hostname of the Bucket.

    TYPE Name Value
    CNAME example.com <bucket_name>.<region>.your-objectstorage.com

    Note that it can take several hours to propagate.


  1. Check the connection

    You can use nslookup to check if the changes were already applied:

    nslookup example.com

    Once the CNAME record works, you can use curl to check if you can successfully access the Bucket data via your domain. Note that the host header of the request has to be the Bucket URL. For now, you can set the host header in the curl request. If your domain doesn't have an SSL certificate, additionally add the flag --insecure.

    curl -H "Host: <bucket_name>.<region>.your-objectstorage.com" --insecure https://example.com/test.txt

  1. Overwrite the host header via a provider

    Some providers offer the option to overwrite the host header of incoming requests.

    Cloudflare, for example, offers this feature to customers with the Enterprise Plan:

    • Select your domain

    • In the left menu bar, navigate to "Rules" » "Overview"

    • Select + Create rule » Origin Rule

    • Set to which incoming requests this rule should be applied

      Field Operator Value
      Hostname equals example.com
    • For "Host Header", select the option Rewrite to... and enter your Bucket URL

      cloudflare cname header


  1. Overwrite the host header in a script

    If you can't change the host header via your provider and you're using the domain in a script, you can change the header via a short code snippet at the beginning of the script. Here's an example for Python:

    import urllib.request, ssl
    
    def fetch(url):
        req = urllib.request.Request(url, headers={
            "Host": "<bucket_name>.<region>.your-objectstorage.com"
        } if "example.com" in url else {})
    
        # If your domain doesn't have an SSL certificate, use the line below instead.
        #return urllib.request.urlopen(req, context=ssl._create_unverified_context()).read().decode()
        return urllib.request.urlopen(req).read().decode()
    
    print(fetch("https://example.com/test.txt"))

When you access your domain, the request should now get forwarded to the Bucket.