346 words · 2 min read
First, a little bit of history.
I have been running websites—personal or otherwise—on-and-off for long enough to remember Geocities. Although I wouldn’t claim to be an expert, I’ve seen and done quite a bit over the years, from hand-coding HTML files and uploading files via FTP to running Wordpress on LAMP and LEMP stacks and experimenting with Varnish Cache.
I stopped making websites for a while before building this website with static site generators (first with Jekyll, then with Hugo). Static sites are simpler, cheaper to run, and with far better performances than dynamic sites such as Wordpress.
Initially, I put this website on Github Pages, which is free and fast, but lacks flexibility. For months, I’ve been itching to migrate (the move to Firebase proved short-lived) while dreading the prospect of having to configure and maintain a server.
Then I discovered Caddy web server, the easiest-to-set-up web server I’ve ever used.
Setting up Caddy
At the most basic level, the configuration file,
Caddyfile, can be as short as this:
example.com:443 root /path-to-your-site-root/
And this is all you need to enable HTTPS with a certificate issued by Let’s Encrypt. No additional work required!
Note: since this website is behind Cloudflare, you won’t see Caddy in the response header, and the certificate is issued through Cloudflare; the Let’s Encrypt certficate is used for traffic between the origin server and Cloudflare.
To allow non-root user to bind to port 80 and 443, run the following command in your terminal:
sudo setcap cap_net_bind_service=+ep /path-to/caddy
Finally, set up a systemd service with the following unit file:
[Unit] Description=Caddy HTTP/2 web server %I Documentation=https://caddyserver.com/docs After=network.target [Service] User=username LimitNOFILE=8192 Environment=STNORESTART=yes ExecStart=/path-to/caddy -agree=true -conf=/path-to/Caddyfile Restart=on-failure [Install] WantedBy=multi-user.target
Save it as
/etc/systemd/system/caddy.service, then run these commands:
sudo systemctl daemon-reload sudo systemctl enable caddy.service sudo systemctl start caddy.service
Now, Caddy web server will start on boot.
Download Caddy here and try it out now.