Serving static files using Google Cloud CDN + Storage Bucket
Google cloud CDN is — low latency, distributed content delivery solution. It has more than 100 POP (Point of presence) to make your assets highly available.
The Cloud CDN content delivery network works with HTTP(S) load balancing to deliver content to your users. The HTTP(S) load balancing configuration specifies the frontend IP addresses and ports on which Cloud CDN receives requests and the backends that originate responses to those requests.
We will see how the above definition works step and step, and also we will configure a cdn using GCloud Platform with SSL ( HTTPS) support.
— — — — — — — —
Before proceeding further, lets see what are the initial steps to be taken to start configuring cdn according to this tutorial…
- You should have knowledge on configuring DNS records.
- You must already have an active domain and access to its control panel
- A GCloud Project
A. Create a Storage Bucket
— — — — — — — — — — — — — — — —
- Go to Google Cloud Platform ( https://console.cloud.google.com) and select your project.
- Search for “Storage” and click on “Storage” from the drop down or click on storage from left nav bar -> browse or check this link https://console.cloud.google.com/storage.
- Click on “CREATE BUCKET” button from top.
- Choose bucket name -> Select multi-regional -> your preferred bucket location.
- Click on “Create”
B. Creating Load Balancer
— — — — — — — — — — — — — — — —
- Search for Network Services -> Click on Load Balancing from left navigation drawer( See under Networking section ) or search from top search bar.
- Click on CREATE LOAD BALANCER -> Select HTTP(S) Load Balancing -> Start Configuring.
- Select Backend Configuration
- From right side select Backend Buckets -> Select your previously created bucket
- Select Frontend Configuration.
- From right side Name section -> Give name to your New Frontend IP and Port
- Select protocol HTTPS ( make sure you have an active domain or subdomain )
- From Certificate section, click on Create a New Certificate.
- Give a name to your new SSL certificate
- Select Create Google-managed certificate as create mode( Google mainly uses Lets Encrypt as CA )
- In domain section, give a subdomain*** name (eg. assets.example.com) that you will use for static assets serving. *** Assuming you currently does not have that sub-domain and you have access to domain provider to create one.
- Click on create
- Once created, again click on Load Balancing from left navigation
- Now you will see Load Balancers created by you. Click on Frontends tab
- Search for previously created config and note down the IP ADDRESS.
- *** Now go to your domain provider’s site and create a subdomain that should point to previously created frontend ip address. This subdomain can be served over https because google has already activated ssl for this.
C. Adding Load Balancer to CDN
- Go to Cloud CDN under Network Services from left nav
- Click on ADD ORIGIN
- Select your previously created Load Balancer
- Click on Add
Now you have successfully created a fully managed cloud cdn that is served over https.
To see if your domain ssl is successfully verified…
- Go to Load Balancing section from left bar -> Under Load Balancers tab and Name Column -> click on your previously created LB
- This will open Load balancer details section
- Under Frontend Section -> Click on your certificate under Certificate column.
- Check this image
To see what these statuses mean, check this link https://cloud.google.com/load-balancing/docs/ssl-certificates?hl=en_GB&_ga=2.131299983.-1697683271.1535389579&_gac=1.229135598.1549389793.Cj0KCQiAheXiBRD-ARIsAODSpWP6ccw-mH7igkjw7pYZdPpVsAbB9ceVWE7ed3bQfD-PT4KSVWfNwFsaAnY3EALw_wcB#domain-status
Add some images or static files to your bucket and access them using your subdomain. Eg. https://assets.example.com/my_image.jpg