30-minute project: caddy-static
I host a number of static websites on my personal server. Over the years, they have been served by a variety of web servers, but I recently decided I wanted to make it easy.
So, I looked for a modern and minimalistic web server that supported a feature of the venerable thttpd
That feature is automatic virtual hosts. The main idea is that you have a folder and in there a bunch of subfolders, each one is a site. And the name of the folder is the name of the site.
So, if I have /srv/ralsina.me
then when a user asks for http://ralsina.me
they get that. And if I have /srv/whatever.com
and
the user asks for whatever.com they get that.
Also, if a site is reachable with more than one name, then just add symlinks and it should just work.
I found a way to do it using NginX but that's far from minimalistic.
So, I looked around and found that Caddy was pretty close except it didn't do the automatic stuff.
So, I wrote the missing bit, threw everything in a docker container and now I have a 30-minute project that serves all my static sites.
Here's the docker compose I am using:
version: "3.8"
services:
web:
logging:
driver: journald
options:
tag: web
container_name: web
stdin_open: true
tty: true
ports:
- 8080:8888
volumes:
- /data/websites/:/srv/
image: ghcr.io/ralsina/caddy-static-arm64:latest
restart: always
networks: {}
And here's the project: caddy-static
It probably needs some tweaking for anyone else specially in the Caddyserver
config and maybe in the template it uses to generate sites
which is hardcoded.
If anyone actually uses this I can make those things configurable.