Switching to Google Cloud

I decided to take advantage of Google Cloud free tier & switch all of my sites over. I’m mostly happy with the results.

Originally I had planned on putting my content on Google Cloud storage (which is like AWS S3) and then pointing a load balancer at that. This worked well, I setup load balancer listeners for both https and http and pointed those at the storage bucket I had created. The first thing I had an issue with was that the IPs for the load balancer http and https were different so I had to reserve an IP, assign it to both http and https and then point the A record at that. After this everything worked!

Unfourtantly I could not force the load balancer to redirect http traffic to https. Therefore I switched my load balancer to point at a compute instance setup with Nginx which is also on the free tier. Here is my config for that:

server {
    listen       80;
    server_name  raymondjcox.com www.raymondjcox.com;
    root   /var/www/raymondjcox.com;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

    if ($http_x_forwarded_proto = 'http') {
       return 301 https://raymondjcox.com$request_uri;

    if ($host = 'www.raymondjcox.com' ) {
       return 301 https://raymondjcox.com$request_uri;

    location / {
        index  index.html index.htm;

    location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
        expires 30d; # expires after 30 days
        add_header Cache-Control "public"; # clients can cache

An important key here is $http_x_forwarded_proto which is what something the google load balancer sends to let you know if it’s http or https traffic. Also, important to note that ssl termination is done at the load balancer level so this can listen on port 80.

Homebrew switch & pin

Yesterday I updated and upgraded my Homebrew packages

$ brew update && brew upgrade

It seemed to work fine. The next day I restarted my computer and noticed that Postgres hadn’t started. When I tried to start it I got this error message:

$ pg_ctl -D /usr/local/var/postgres start
server starting
FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.5, which is not compatible with this version 9.6.5.

What happened? Postgres updated to version 9.6.5 but my database was initialized to 9.5. Whoops. To list all installed versions of Postgres I used this command:

$ brew ls --versions postgresql
postgresql 9.5.5 9.6.1 9.6.2 9.6.3 9.6.4 9.6.5

I then switched back to a Postgres version that was already installed (in my case 9.5.5):

$ brew switch postgresql 9.5.5

After doing this I did a little research and discovered brew pin:

$ brew pin postgresql

This stops Postgres from updating when I brew upgrade so I will never have this problem again (with Postgres).