Getting started with Caddy
Recently I’ve been enjoying using Caddy web server to get automatic-HTTPS websites. I took the time to package it for Fedora and CentOS/RHEL to make it more accessible and more maintainable. This guide demonstrates how to use those packages.
In order for Caddy to provision your Let’s Encrypt certificates as soon as it starts, you will need two things configured beforehand.
- a DNS record pointing your domain to your server’s IP address
- port 80 allowed for the ACME HTTP challenge
Since you’ll need port 443 open later anyways, just go ahead and open both now.
firewall-cmd --permanent --add-service=http --add-service=https
For the rest of the guide, make sure you replace
example.com with the actual domain name you want to use.
CentOS and RHEL (make sure EPEL is enabled first):
yum install caddy
dnf install caddy
Put your own content in
/var/www/example.com, or use this example index file to get started now and swap in your own content later.
mkdir -p /var/www/example.com
echo '<h1>Hello world!</h1>' > /var/www/example.com/index.html
If you care about selinux (you should), restore the file context for your content files and directories.
restorecon -r /var/www
Create a Caddyfile as
/etc/caddy/conf.d/example.com.conf. Files in
/etc/caddy/conf.d ending in
.conf will be automatically imported by the global Caddyfile
/etc/caddy/caddy.conf, which in turn is read by the systemd service unit.
Enable and start the Caddy daemon.
systemctl enable --now caddy
You should now be able to open https://example.com in your browser and view your content.