0xDEAD Unicornz Ascending to a Cloud
What time is it? Migration time! Long story short I’ve decided to play a bit with Google Cloud services and Go. I’m really impressed with the platform so far - it’s awesomely documented and super easy to use. I was impressed to the point I’ve decided to move my blog from a VPS to Google Cloud Storage just to see how it goes.
Here is a step by step instruction
Few pitfalls
Access
It makes sense to create default ACL for the bucket permitting read access to all users for all files:
gsutil defacl ch -u AllUsers:R gs://<bucket_name>
otherwise next time you update the blog new files will be not accessible until permissions fixed.
CNAME DNS record
The blog was hosted under domain deadunicornz.org. In order to serve it from Google storage it’s needed to create CNAME record pointing deadunicornz.org to c.storage.googleapis.com. It’s not possible because domain name should not have any DNS records but CNAME by RFC, and you can’t get rid of MX and NS records configured for your domain name.
That’s why we have www
domain! www.deadunicornz.org points to c.storage.googleapis.com
and everything works as expected except if you open deadunicornz.org without www
-
deadunicornz.org domain still points to VPS. To fix this I’ve changed Nginx config for
deadunicornz.org on VPS to
server {
listen 80 default_server deferred;
server_name deadunicornz.org;
return 301 http://www.deadunicornz.org$request_uri;
}
as you can see a permanent redirect deadunicornz.org > http://www.deadunicornz.org was configured. Note though I didn’t bother to configure SSL - first there is nothing to protect, blog is purely static and no authorization/authentication information passed to/from the site. The second reason is because Google Cloud Storage does not support SSL connections (so far?) anyway.
404 page
404 page is not served by Nginx anymore, so I had to create a basic one and put into
blog bucket to avoid displaying a default ugly error page provided by the storage.
You point to your custom 404 page using gsutil web
command:
gsutil web set -m index.html -e 404.html gs://<bucket_name>
-m
option here specifies the object name to serve when a bucket listing is requested.