I built a cheap CDN for my static website based on nginx’s HTTP caching.
Context. Here’s are some parts of my cache configuration:
proxy_cache_key "$scheme://$host$uri";
proxy_cache_valid 200 301 302 1200d;
I have one origin machine and around 10 edge machines all proxying back to the origin at various locations. The origin also doubles up as one edge. Cache on all of these machines are warmed up.
Now, every now and then content in a particular URL will be updated. With a sticky session in a load balanced environment this means that cache on one edge and the origin will be invalidated using proxy_cache_bypass mechanic (I updated content from the admin section and visit the URL. Nginx does a proxy BYPASS refreshing the content because I have a set cookie.)
The problem here is that in all the other edge locations the cache validity for that particular URL is a max of 1200 days. Which means they’ll never fetch from the origin.
In a scenario like this, how I ensure the cache is updated on all my edge servers?
One approach suggested here is to do something like this:
Loop through all the edges and run
curl -o /dev/null -k -I --resolve cdn.yourdomain.com:80:127.0.0.1 https://cdn.yourdomain.com/img/logo.png
Is there a right approach to this?