Serving WordPress over HTTPS with Caddy and DigitalOcean Spaces

The other day, I thought to update this blog, and in turn, the service stack that I use to host it so that I could solve some general problems I had been experiencing with maintenance. Specifically, I was trying to solve 4 problems –

  1. Having to jump in my server every 90 days or so to renew my free LetsEncrypt SSL certificate
  2. Reduce the amount of storage my daily backups used on the local filesystem
  3. Reduce the amount of storage my media files used on the local filesystem
  4. Use a custom domain with SSL for object storage (DigitalOcean Spaces)

In an attempt not to re-invent the wheel, here’s a guide that helped with setting up WordPress to work with Caddy Server.

Once I had Caddy Server setup and running WordPress, I only had to –

  1. Edit the Caddyfile slightly to proxy my custom subdomain to Spaces. Below is the host block I had to add to my Caddyfile to proxy the ‘go.goke.me’ domain to my DigitalOcean Spaces bucket. There are other variations of this setup, feel free to drop a comment if you’re looking for help with something different.
    sub.domain.com {
     proxy / https://{bucket}.{region}.digitaloceanspaces.com {
     header_upstream Host {bucket}.{region}.digitaloceanspaces.com
     }
     tls your@email.address
    }

    Goes without saying, you need to add an A record pointing your chosen subdomain (in my case ‘go.goke.me’) to this server as well. I used a CNAME to my root domain instead, since I used the same web server for both.

  2. Setup the Media Cloud plugin to offload all my media to Spaces. After installing the plugin on WordPress, I had to set it up and have my media library uploaded to Spaces. Here’s my setup. Under Storage Settings, you want to enable (1) Delete Uploaded Files to actually save storage space. I had this disabled to ensure things work seamlessly before deleting local files. (2) & (3) enable us use the custom domain we set up on our Caddyfile.
  3. Setup the UpdraftPlus plugin to upload backups to Spaces as well.
    • Setup Daily Backups: Settings >> UpdraftPlus Backups >> Settings
    • Take Your First Backup:¬†Settings >> UpdraftPlus Backups >> Current Status >>¬†[click] Backup Now

With the setup above, I now use Caddy Server for both my WordPress app server and as a custom domain w/SSL proxy for DigitalOcean Spaces, solving problems 1 and 4. Problems 2 and 3 are solved by offloading my media library and backups with the plugins above. It is advised to leave the Spaces instance Private on DigitalOcean, as the plugins should set the proper permissions for each object you upload. Media Library files will be public, and backups will be private.

This is mostly just to illustrate the cool things you can do with both Caddy Server and DigitalOcean Spaces integrated with WordPress. For example, I used a high CPU droplet for this blog, which means I have limited storage. But storing objects on DigitalOcean Spaces practically gives me limitless space for media and backups, which consume the most storage on my blog. Certainly, you can use other options for object storage, but in my assessment so far (and with free uploads), Spaces is the best value object storage offering currently available.

Finally, Caddy Server serves in HTTP/2 natively and helps you manage your LetsEncrypt certs. It’s a cool piece of tech, and almost too easy and awesome not to use for most cases. And oh, it’s written in Go.

Any questions? Drop a comment or tweet at me:

@gokejnr help: Click to Tweet

Share your thoughts...