I wrote a quick Python server to serve resampled images. For example, a URL might look something like http://images.domain.com/resample/100x100/9f362e1994264321.jpg
. Being that resampling images is expensive, a caching layer is necessary. It seems like an nginx reverse-proxy would be a good option for this, and here and here seem like good places to start.
However, there's a problem. There are millions of images, so by storing http://images.domain.com/resample/100x100/9f362e1994264321.jpg
in the filesystem as /home/nginx/cache/resample/100x100/9f362e1994264321.jpg
(or something of the sort), eventually cache/resample/100x100/
will have millions of files in it, which will make file lookups very inefficient.
I deal with this problem while storing the original images by distributing them among many subdirectories, eg, 9f/36/9f362e1994264321.jpg
. However, I'm not sure how I might do the same with nginx. I could change the URL to do likewise, and I will if that's the only solution, but I'd rather keep the URL as pretty as possible.
Can I do this with nginx? If not with nginx, can I do it something else, like varnish?