Nov 25, 2022 1 min read

Caddy Free Web Server with Automatic SSL

Caddy Free Web Server with Automatic SSL
Caddy Server 2 alternate to apache and nginx
Table of Contents

Caddy is a powerful, extensible platform to serve your sites, services, and apps, written in Go.

Installation

Debian, Ubuntu, Raspbian

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

Create Caddy Service

sudo systemctl enable caddy

Edit CaddyFile

sudo vim /etc/caddy/Caddyfile

Add the Below lines to Caddyfile Config

example.com {
	reverse_proxy localhost:5000
}
💡
In this tutorial, replace example.com with your actual domain name.

Set your domain's A/AAAA records to point to your server. You can do this by logging into your DNS provider and managing your domain name.

Before continuing, verify the correct records with an authoritative lookup. Replace example.com with your domain name, and if you are using IPv6 replaces type=A with type=AAAA:

curl "https://cloudflare-dns.com/dns-query?name=example.com&type=A" \
  -H "accept: application/dns-json"

Also, make sure your server is externally reachable on ports 80 and 443 from a public interface.

Start Caddy Server

Then from the same directory, run:

sudo caddy stop
sudo caddy start

You can use caddy reload to reload the config live.

You will see Caddy provision a TLS certificate and serve your site over HTTPS. This was possible because your site's address in the Caddyfile contained a domain name.

For More Information visit caddyserver.com

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to BugFix.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.