After your VM is created, you can visit its IP address in your browser, where you will see a welcome page that will guide you to a functional site:
1- Point your domain’s A/AAAA records at your VM’s IP address(es).
2- Upload your site’s files to /var/www/html
.
3- Edit your Caddyfile at /etc/caddy/Caddyfile
:
a- Replace :80
with your domain name
b- Change the site root to /var/www/html
4- Reload the configuration: systemctl reload caddy
That’s all there is to it! Caddy does the rest. It will keep your certificates renewed while it serves your sites, and it even redirects HTTP requests to HTTPS.
To make sure it worked, simply visit your site in your browser by using your domain name! Note that it may take up to a minute for Caddy to obtain a TLS certificate. If there were any problems, the welcome page has some suggestions. Usually, errors on the first run are related to improper DNS configuration, slow DNS propagation, or misconfigured ports/firewalls.
You can additionally set up more features in the Caddyfile such as compression, reverse proxying, template evaluation, and much more. It also has an API if you want to programmatically manage its configuration.
See the Caddy 2 documentation for details.