Notes on hosting a static website on Google Cloud.
There are two ways of approaching this:
- Google Cloud Storage
- Google App Engine
Google Cloud Storage
Google Cloud Storage in combination with a Load Balancer for HTTPS
To create a bucket (documentation):
To copy all files in a folder to the bucket, use the --recursive
CLI argument
Setting up the Load Balancer requires an IP address, but there is a cost tied to reserving an IPv4 address. I’m attempting to use an IPv6 address instead and see how it goes.
Google App Engine
Google App Engine allows you to easily set up a server that hosts the website content. The documentation provides all the required information, but I wanted to give more context on the Google App Engine example.
Even though the real webserver is not used as such, it is still required to create one. This can be done by following for example the node.js tutorial, but any runtime would work.
To avoid exceeding the Google App Engine free tier quota, be sure to set maximum instances in automatic scaling to 1 by adding
to the app.yaml
file.
Mapping a custom subdomain
Finally, you could map a custom domain to this application. I had one additional complexity: the main WordPress website is still running on the original domain and I want the webserver to be accessible from a subdomain. It could be that there’s a better way of doing it, but using this method it’s possible to map just a subdomain to the Google Cloud.
The method works by registering the subdomain in Google Webmaster Central, which can be done even if the naked domain has already been verified. Afterward, the subdomain can be added to the Google Cloud Console. This way, the A and AAAA DNS records are generated for the subdomain instead of the naked domain.