Sunday, June 7, 2020

How to enable Google CDN for custom origin websites | Google CDN for external websites

How to enable Google CDN for custom origin websites | Google CDN for external websites


Introduction


Cloud CDN by Google is a low-latency content delivery solution for small to enterprise business. Cloud CDN (Content Delivery Network) uses Google's globally distributed edge points of presence to cache external HTTP(S) load balanced content close to your users, when a user goes to your website, they retrieve your content from the nearest CDN location rather than from your web server. Caching content at the edges of Google's network provides faster delivery of content to your users while reducing serving costs.

Some of the features of Google Cloud CDN
  • HTTP/2 support
  • Global distribution with anycast IP
  • Integrated with Google Cloud – Cloud Monitoring and Cloud Logging
  • Purge cache instantly
This tutorial explains the steps required to enable the Google CDN in front of the custom origin websites running outside of Google Cloud platform.

Prerequisite

  • Google Cloud Account
  • Externally accessible websites


Scenario

I have a website running in external server – test.albinsblog.com, I want to activate the CDN in front of my website.

google-cdn-custom-origin


Steps

  • Register for a Google Cloud Account
  • Create new HTTP(S) Load Balancer
  • Enable CDN
  • Enable A-Record for DNS


Register for a Google Cloud CDN


If you not enabled for Google Cloud CDN then access https://cloud.google.com/cdn and click on “Try Cloud CDN Free”

google-cloud-cdn-setup

google-cloud-cdn-setup

Configure the Payment Profile. This will take sometime to complete the configuration; you should be seeing “Compute Engine is getting Ready”, once after the Compute Engine is ready you will see the option to add CDN Origin.

google-cloud-cdn-setup


Create new HTTP(S) Load Balancer


As a first step, let us configure the new HTTP(S) Load Balancer. Click Add origin on the previous screen and Click on Continue on the Next screen. Select “Use a custom origin” and click on “Create a load balancer.

google-cloud-cdn-setup

Enter a unique name for the load balancer. Click on back end configuration and create a backend service

google-cloud-cdn-setup-backend


Enter a name and select backend Type as “Internet Network endpoint group”, change the protocol as required – this protocol will be used by Google Load balancer to connect to the origin server. I am going with HTTP protocol for the demo

Select “Create Internet network endpoint group” from "Internet network endpoint group" dropdown

google-cloud-cdn-setup-backend

Enter a name for Internet network endpoint group, select “Network endpoint group type” as Network endpoint group (Internet).

Add the default port to connect to origin server – my case the server is accessible through port 80, enter the IP address or the Fully qualified name of the origin server – I am configuring the IP address

Click on Create
google-cloud-cdn-setup-network-endpoint

Select the created Internet network endpoint group in backend service configuration screen and click on Done

Select "Enable Cloud CDN" and click on create

google-cloud-cdn-setup-backend

Select Host and Path Rules and enable the require rules – I am going with default rule configurations 

Now click on Frontend Configurations


google-cloud-cdn-host-path-rules

Enter a name

Select the protocol users uses to connect to the website, the SSL certificate should be uploaded if the protocol is selected as HTTPS with supported Domains.

google-cloud-cdn-frontend-configuration

You can upload the existing certificate or create google managed SSL certificate

I am going with HTTP for the demo

google-cloud-cdn-ssl

Create new IP address – the default IP address lives for short time, create a static IP address.

google-cloud-cdn-static-ip-address

google-cloud-cdn-static-ip-address

Review the configurations and click on Create

google-cdn-loadbalancer-configurations


Now the HTTP(S) Load Configuration is ready and enabled with CDN

Enable A-Record for DNS


Now your website is accessible through the Google CDN Front end IP, add a A-Record pointing to the Frond End Ip for the website DNS through your network provider – my case cloudflare

e.g test.albinsblog.com A-Record 34.120.141.59

Now test.albinsblog.com should be accessible through Google CDN, you can monitor the traffics through console and also the cache path can be invalidated whenever required.

google-cdn-motitoring


My backend server is running on Apache, I have enabled the Virtual host configuration to support test.albinsblog.com - Google CDN sends the DNS values as part of Host header, enable different virtual host to support multiple websites.

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:\opt\communique\dispatcher\cache"
    ServerName test.albinsblog.com
    ServerAlias localhost

    RewriteEngine On

   RewriteRule ^/test.html$ http://test.albinsblog.com/content/wknd/fr/fr.html [L]

   <Directory />

Options Indexes FollowSymLinks Includes   
# Set includes to process .html files
AddOutputFilter INCLUDES .html
AddOutputFilterByType INCLUDES text/html
AllowOverride None
    </Directory>
</VirtualHost>



Conclusion


This concludes CDN is enabled on the custom origin website. The same setup can be used to support multiple websites, the backend(origin) should support the required DNS – Google CDN sends the Host header with the DNS value the user is accessing from the browser. The host header in the origin server can be used to enable the DNS specific functionalities. The Google CDN improves the website performance by caching and serving the website content from network of servers across the world, the server will be contacted in case the requested content is not available in the CDN cache.

1 comment:

  1. How to setup cloud cdn please help me , i will pay , i want to setup for my external website, which is hosted in Amazon ec2, help me

    ReplyDelete