10/25/2024  

  David Batey

How to set up custom domains for Google Cloud Storage

5 min read

Table of contents

  1. Introduction
  2. Create a Google Cloud Storage bucket
  3. Setup your Qloaked application

Introduction

A Google Cloud Storage bucket is a great way to store static assets for your website.

However, it doesn't support custom domains out of the box with HTTPS without setting up an external load balancer Google Cloud Storage Hosting but fortunately Qloaked can help make this a breeze.

This guide will show you how to set up Qloaked to proxy requests to your bucket and add a custom domain.

Create a Google Cloud Storage bucket

Login to the Google Cloud Console (https://console.cloud.google.com/)

Navigates to the GCS buckets section

Navigate to GCS buckets

Click the button to create a new bucket

Createa a bucket

Follow the setup wizard to create a new bucket and make sure to untick "Enforce public access prevention on this bucket"

Setup bucket

Now we need to enable static website hosting for the bucket by making its contents publicly accessible.

In the bucket settings, go to the permissions tab and click on the grant access button.

Grant access

Now we need to give "allUsers" the Storage Object Viewer role.

Grant all users principalStorage viewer access

Now when you save that you'll get a popup asking you to confirm that you want to allow public access to the bucket.

Allow public access

Now you're all set to upload your static assets to the bucket and if you send someone a link they'll be able to access it.

Let's setup a custom domain now to use with this bucket. It could be any domain you own or a customers domain etc...

Setup your Qloaked application

Login to your Qloaked account here (Qloaked Login)

Click on the "Applications" menu drop down and then click the "Create Application" button.

Applications menuCreate application button

This will then start the application creation wizard. In our example the application is the GCS bucket.

Application name

Now set GCS to be the application endpoint (https://storage.googleapis.com) and expand the "Advanced" section to set the host header to the bucket domain (storage.googleapis.com).

Application endpointApplication host header override

Now any requests coming into this application will look like requests to the bucket domain to Google.

Set an optional application CNAME - This is what you'll provide to your customers to point to this application.

Application CNAME

Click the "Save" button to create the application.

Application created

You can now point your custom domain to either the application CNAME or the application-name.domains.qloaked.com.

Now if you visit your new domain e.g. www.newdomain.com/bucket-name you will see the buckets contents and secured on https and you will see the new domain in your Qloaked account.

Domain Created