Serve a Zola site using Caddy
Table of Contents
To serve a Zola site using Caddy, simply ==configure Caddy to serve the static files generated by your Zola build process within the designated root directory==, leveraging Caddy's "file_server" directive to deliver the static content directly to visitors; essentially treating your Zola site like any other static website.
Key steps:
- Build your Zola site: Run your Zola build command to generate the static HTML, CSS, and JavaScript files in the designated output directory.
- Caddy configuration:
- Create a Caddyfile:
yourdomain.com {
root /path/to/zola/output_directory
file_server
gzip
}
Explanation:
yourdomain.com: Replace with your actual domain name.root /path/to/zola/output_directory: Point this to the directory where your Zola build generated static files.file_server: Tells Caddy to serve static files from the specified root directory.gzip: Optionally enable Gzip compression for better performance.
Alternatively run a different http service and just have caddy reverse proxy it. Something like :
# reverse proxy approach. if service is running locally on http
blog.cielago.xyz {
reverse_proxy 127.0.0.1:8090
}
Start Caddy:
Run the Caddy command to start the server, which will now serve your Zola site using the configured domain.
systemctl start caddy.service
Benefits of using Caddy for Zola:
Automatic HTTPS:
Caddy automatically handles Let's Encrypt certificate management, providing secure HTTPS connections by default.
Simple configuration:
The Caddyfile syntax is considered user-friendly, making it easy to set up a Zola site.
Performance optimizations:
Caddy can automatically optimize static file delivery with features like caching and compression.
Server commands
(re)start the caddy service
systemctl restart caddy.service
Tail the logs
journalctl -xeu caddy.service
References
- How to serve a static site using Caddy. A more detailed explanation.
- Caddy File Docs
- Caddy homepage