~ The automatic HTTPS capabilities of Caddy
» By Joren on Wednesday 18 January 2023This blog has been running on Caddy for the last couple of months. Caddy is a http server with support for reverse proxies and automatic https. The automatic https feature takes care of requesting, installing and updating SSL certificates which means that you need much less configuration settings or maintenance compared with e.g. lighttpd or Nginx. The underlying certmagic ACME client is responsible for requesting these certificates.
Before, it was using lighttpd but the during the last decade the development of lighttpd has stalled. lighttpd version 2 has been in development for 7 years and the bump from 1.4
to 1.5
has been taking even longer. lighttpd started showing its age with limited or no support for modern features like websockets, http/3 and finicky configuration for e.g. https with virtual domains.
Caddy with Ruby on Rails
I really like Caddy’s sensible defaults and the limited lines of configuration needed to get things working. Below you can find e.g. a reusable https enabled configuration for a Ruby on Rails application. This configuration does file caching, compression, http to https redirection and load balancing for two local application servers. It also serves static files directly and only passes non-file requests to the application servers.
(cachestaticfiles) { @staticFiles { file } header @staticFiles Cache-Control "public, max-age=604800, must-revalidate" } (railsdefaults) { #compress responses encode zstd gzip #redirect from http to https @http { protocol http } redir @http https://{host}{uri} @notStatic { not file } import cachestaticfiles reverse_proxy @notStatic localhost:{args.0} localhost:{args.1} file_server } example.com { root * /var/www/example.com/current/public import railsdefaults 10000 10001 }
If you are self-hosting I think Caddy is a great match in all but the most exotic or demanding setups. I definitely am kicking myself for not checking out caddy sooner: it could have saved me countless hours installing and maintaining https certs or configuring lighttpd in general.