TIL how to use caddy as automatic https reverse proxy

1 minute read Published:

Short howto: download and configure caddy - an automatic https (!!!) webserver

Hey Blog! Long time no see…

Today I will show you how to download and execute caddy - an automatic https web server and reverse proxy written in Go!

be me.
browse the interwebs.
see caddy - a fully automatic https server
togoodtobetrue.jpg
write script to download caddy from their cdn
and create a Caddyfile on a spare server
itsworking.exe
best day ever - free ssl certs with auto renewal

You can download caddy here. Give it a try with a spare (sub-)domain you find laying around.

My download and setup script:

#!/bin/sh

TARBALL=caddy.tar.gz
TARGET=/opt/caddy

echo "downloading caddy"
wget -O $TARBALL "https://caddyserver.com/download/build?os=linux&arch=amd64"

echo "creating target directory"
sudo mkdir -p $TARGET

echo "extracting caddy"
sudo tar -xvzf $TARBALL -C $TARGET &&

echo "allow non privileged users to run caddy and bind to privileged ports"
sudo setcap "cap_net_bind_service=+ep" $TARGET/caddy

echo "removing tarball"
rm $TARBALL

Configuring caddy

$ sudo su
$ mkdir /var/log/caddy
$ mkdir /var/caddy/ && cd $_
$ mkdir www
$ echo "it's working!" > www/index.html
$ vim Caddyfile

Caddyfile

yourdomain.com {
	root /var/caddy/www
	log / /var/log/caddy/access.log "{combined}"
	gzip
	tls [email protected]
}

Starting

$ cd /opt/caddy
$ ./caddy -agree -conf /var/caddy/Caddyfile

Try it out in your browser by typing: https://yourdomain.com!