How I setup a new website on caddy server

on Michael Harley's blog

1 min read

I've decided to move my online identity to a new name space: michaeharley.net. This means I need to setup a new website on my VPS / Caddy Server.

Setup DNS #

Add the following DNS records for the domain.

Type: A Hostname: * IP Address: 69.61.19.181

Type: A Hostname: @ IP Address: 69.61.19.181

Type: A Hostname: www IP Address: 69.61.19.181

Configure Caddy #

  1. SSH to the server: ssh cyberian@69.61.19.181
  2. Create new directory: sudo mkdir /var/www/michaelharley.net
  3. Update permissions on the new directory: sudo chown cyberian:cyberian /var/www/michaelharley.net
  4. Edit caddyfile: sudo nano /etc/caddy/Caddyfile
  5. Insert this json then save:
www.michaelharley.net {
        redir https://michaelharley.net{uri}
}

michaelharley.net {
        root * /var/www/michaelharley.net
        file_server
        encode gzip
        handle_errors {
                @404 {
                        expression {http.error.status_code} == 404
                }
                rewrite @404 /404.html
                file_server
        }
}
  1. Format caddyfile: sudo caddy fmt /etc/caddy/Caddyfile --overwrite
  2. Copy a test file to the server: rsync -rtv --delete --quiet --human-readable -e 'ssh' ~/Projects/michaelharley/ cyberian@69.61.19.181:/var/www/michaelharley.net
  3. Reload caddyfile: caddy reload --config /etc/caddy/Caddyfile

Done! You're welcome, future me.

Filed under: Caddy Server, Note To Self
Michael Harley

About the author

Hello, I'm Mike. I care about the IndieWeb, digital sovereignty, and the open web. I'm a developer and team lead based in Richmond, VA, and this site is my corner of the internet.

Directory: /home · /about · /contact · /posts · /sitemap