How I setup a new website on caddy server
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 Capsul VPS / Caddy Server.
Setup DNS
Add the following DNS records for the domain.
Type: A
Hostname: *
IP Address: 69.61.2.205
Type: A
Hostname: @
IP Address: 69.61.2.205
Type: A
Hostname: www
IP Address: 69.61.2.205
Configure Caddy
- SSH to the server:
ssh cyberian@69.61.2.205
- Create new directory:
sudo mkdir /var/www/michaelharley.net
- Update permissions on the new directory:
sudo chown cyberian:cyberian /var/www/michaelharley.net
- Edit caddyfile:
sudo nano /etc/caddy/Caddyfile
- 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
}
}
- Format caddyfile:
sudo caddy fmt /etc/caddy/Caddyfile --overwrite
- Copy a test file to the server:
rsync -rtv --delete --quiet --human-readable -e 'ssh' ~/Projects/michaelharley/ cyberian@69.61.2.205:/var/www/michaelharley.net
- Reload caddyfile:
caddy reload --config /etc/caddy/Caddyfile
Done! You're welcome, future me.