While Traefik is a really great and modern load-balancer, it does not support caching at the moment.
This project aims to solve that by putting Nginx, a caching load-balancer and reverse proxy in front of it.
This is written for Docker, but the nginx config can be applied to any configuration.
- Cache is stored and served entirely from memory
- Returns stale items (and refreshes it), so cached content is always returned
- Only static assets are cached... does not affect changing content like API queries
- HTTP errors like
404
are not cached.
Nginx config can be found in the ./nginx
folder.
Using Docker Compose:
docker compose up -d
Or alternatively, apply nginx.conf to your configuration.
To persist the cache across nginx container restarts or system reboots:
- Remove the
shm_size
line from docker-compose.yml - Mount a folder to store caching data, for example:
mkdir nginx-cache
...
volumes:
- ./nginx:/etc/nginx/conf.d:ro
- ./nginx-cache:/cache
- Change
/dev/shm
in the first line innginx.conf
to/cache
, per the example above. - Run
docker compose up -d
or restart nginx
To check whether an item is cached or not, check the X-Cache-Status
header in response headers.
Here's an example with curl:
~> curl -s -I "http://10.0.0.99/login.html" | grep Cache
X-Cache-Status: MISS
~> curl -s -I "http://10.0.0.99/login.html" | grep Cache
X-Cache-Status: HIT
- add HTTPS support