Caddy
Basic usage of Caddy web server
Caddy is an extensible server platform written in Go. It automatically obtains and renews TLS certificates, making it a great choice for serving secure websites.
Caddy is much easier to configure than Nginx or Apache, and it has a simple configuration file format.
Installation
see Caddy installation guide. Caddy supports Linux, macOS, Windows.
In a Ubuntu system, you can check if Caddy is started with the following command:
1 | sudo systemctl status caddy |
Caddy should be running after installation. it should show the status as active (running)
.
To reload Caddy
1 | sudo systemctl reload caddy |
Visit your site at https://your-domain.com. If you see the Caddy welcome page, it means Caddy is serving your static website correctly.
Serving a Static Website
The Caddy welcome page already has instructions on how to serve a static website. The welcome index page is located at /usr/share/caddy
on Ubuntu.
To serve your own static website, follow these steps:
- Point your domain’s A/AAAA DNS records at this machine.
- Upload your site’s files to /var/www/html.
- Edit your Caddyfile at /etc/caddy/Caddyfile:
- a. Replace :80 with your domain name
- b. Change the site root to /var/www/html
- Reload the configuration:
systemctl reload caddy
- Visit your site!
Here is default content of Caddyfile at /etc/caddy/Caddyfile
that you can modify to serve a static website:
1 | :80 { |
Reverse Proxy
Caddy can also be used as a reverse proxy. This is useful if you want to serve multiple applications on the same domain or if you want to proxy requests to another server.
Update Caddyfile to include a reverse proxy configuration. For example, to proxy requests to a Node.js application running on port 3000, you can add the following to your Caddyfile:
1 | example.com { |
run systemctl reload caddy
to apply the changes.